SOEN228_11w_week_9

SOEN228_11w_week_9 - SOEN228 w11 Week 9 stack operations...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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)
Background 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.
Background image of page 3

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

View Full DocumentRight 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
Background 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
Background image of page 5

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

View Full DocumentRight 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.
Background 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.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Base and index addressing
Background 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
Background image of page 9

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

View Full DocumentRight Arrow Icon
System calls A system call is a call to the operating system to
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/30/2011 for the course SOEN 228 taught by Professor T.fancott during the Winter '11 term at Concordia Canada.

Page1 / 69

SOEN228_11w_week_9 - SOEN228 w11 Week 9 stack operations...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online