{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SOEN228_11w_week_9 - SOEN228 w11 Week 9 stack operations...

Info icon This preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
SOEN228 w11 Week 9 stack operations NASM instructions, examples
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Addressing Bytes and words Memory is organized in addressable units Normally, an addressable unit is a byte (8 bits) Computers usually work with larger units, typically words. These may be 2, 4, or 8 bytes (16, 32, or 64 bits)
Image of page 2
Addressing modes in NASM 1 Immediate Operand The (value of the) operand is contained in the instruction itself (in the displacement field) Example: mov ax, 0x1234 ;Note: in NASM 0x1234 = 1234h Before execution: eax = 1010FEFEh. After execution: eax = 10101234h. Example: mov eax, schar Before execution: eax = 1010FEFEh, the address (memory location) corresponding to schar in the data is 10001000h. After execution: eax = 10001000h.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Addressing modes in NASM 2 Register indirect addressing The specified register contains the address of the operand. We use [ ] to denote indirect addressing. [ebx] -register ebx contains the memory address of the operand, rather than the operand itself (as in the case of ebx instead). Example: mov eax, [ebx] Before execution eax = 0000FEFEh, ebx =00008080h, and 00001010h is stored in from locations 00008080h up to 00008087h. After execution , eax = 00001010h, ebx and memory storage remain unchanged. Compare with : move eax, ebx Contents of ebx are moved into eax A execution eax =00008080h, ebx =00008080h
Image of page 4
Another example Immediate operand mov eax, 4 4 is a decimal value stored in the address field of the instruction. This value is referenced by the instruction. mov eax, ‘4’ in quotes the ascii code for 4 is stored. This is a character
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Addressing modes in NASM 3 Indexed Addressing The address is specified by an index register together with a scale factor. Example: mov ax, [esi*2] Before execution : esi = 1000h Memory address 2000h contains 10h and 2001h contains 1Ah. After execution : ax = 101Ah. A typical use of the indexed addressing is to initialize esi to point to the starting address of a structure data, (example: character string schar). Subsequently, different elements of the array can be accessed (read/written) by incrementing/decrementing/modifying esi.
Image of page 6
Addressing modes in NASM 4 Based and Indexed (with or without Displacement) We can use both the base register (ebx) and the index register (si) together to access a structured data. Example, we use ebx to point to the starting address of schar (i.e., the location that stores schar[0]). By modifying esi, we can access different bytes of the character string schar (“comp”), as in the following. mov ax, [ebx+esi] (based + indexed addressing) Before execution : ebx = 10001000h (starting address of schar), and esi = 2h. After execution : ax = ‘mp’ = 6D70h.
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Base and index addressing
Image of page 8
System Call Addressing conventions in NASM- program segment mov eax, 4 ; select system call #4 to print mov ebx, 1 ; stdout (usually the screen) mov ecx, msg ; start address of message mov edx, len ; length of message int 80h ; invoke the system call
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
System calls A system call is a call to the operating system to perform a function. Assembler system calls are rather primitive. They transmit values through predefined registers to the O/S.
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern