1 / 8

More on operators and procedures in the Linked Library

More on operators and procedures in the Linked Library. Pointers A variable that contains the address of another variable is called a pointer variable. Pointers are essential when manipulating arrays and data structures. Intel- based programs use basic type of pointers, Near and Far pointers.

orpah
Download Presentation

More on operators and procedures in the Linked Library

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. More on operators and procedures in the Linked • Library

  2. Pointers • A variable that contains the address of another variable is called a pointer variable. • Pointers are essential when manipulating arrays and data structures. • Intel- based programs use basic type of pointers, Near and Far pointers. • With the protected mode in this course we use near pointers, so they are stored in double word variables.

  3. Example: • ArrayB Byte 10h, 20h, 30h, 40h • ArrayDW Dword 1000,2000,3000,4000 • The pointers to the above arrays can be define as: • ptrB Dword ArrayB • PtrDW Dword ArrayDW

  4. Example: • TITLE pointers • Include Irvine32.inc • .data • arrayB Byte 10h,20h,30h • arrayD Dword 4,5,6 • Ptr1 Dword arrayB ;pointer to arrayB • Ptr2 Dword arrayD ;pointer to arrayD • .code • main proc • mov esi, ptr1 ;move the address (pointer to arrayB) to esi • mov ebx, [esi] • mov esi, ptr2 ;move the address (pointer to arrayD) to esi • mov eax,[esi] • Exit • Main ENDP • END main

  5. ReadString Procedure • ReadString procedure reads a string input, stopping when the user press the enter key. It returns a count of the number of bytes read in the EAX register. • Before calling read string, set EDX to the offset to an array of bytes where input characters will be stored, and set ECX ( loop counter) to the maximum number of characters to read. • In The next example, the segment calls ReadString, passing ECX and EDX. Notice that we subtract 1 from the buffer size to save a byte at the end of the string for the null terminator

  6. .data • Buffer Byte 50 DUP(0) ;holds the characters • byteCount Dword ? ;holds counter for loop • .code • mov edx, offset buffer ;points to the buffer • mov ecx, (sizeof buffer)-1 ;specify max characters • call ReadString ;input the string • mov bytecount, eax

  7. SetTextColor • The SetTextColor procedure sets the current foreground and background colors for text output. The following color constants are predefined and can be used for both the foreground and background.

  8. These color constants are defined in Irvine32.inc. • The background color must be multiplied by 16 before being added to the foreground color. • The following example, defines yellow characters on a blue background • Yellow + (blue * 16) • Before calling SetTextColor, move the desired color to EAX • Mov eax, white + (blue*16) • Call setTextColor

More Related