64 bits 8 bytes Eg double Instructions can operate on any data size movl movw

64 bits 8 bytes eg double instructions can operate on

This preview shows page 33 - 43 out of 160 pages.

64 bits (8 bytes) E.g., double Instructions can operate on any data size movl, movw, movb Move double word, word, byte, respectively End character specifies what data size to be used
Image of page 33
Rutgers University David Menendez 34 MOV instruction Most common instruction is data transfer instruction Mov SRC, DEST: Move source into destination SRC and DEST are operands DEST is a register or a location SRC can be the contents of register, memory location, constant, or a label. If you use gcc, you will see movl <src>, <dest> All the instructions in x86 are 32-bit Used to copy data: Constant to register (immediate) Memory to register Register to memory Register to register 34 Cannot copy memory to memory in a single instruction
Image of page 34
Rutgers University David Menendez 35 Immediate Addressing Operand is immediate Operand value is found immediately following the instruction Encoded in 1, 2, or 4 bytes $ in front of immediate operand E.g., movl $0x4040, %eax movl %eax 4040 000f 00A1 00A2 memory ADDR
Image of page 35
Rutgers University David Menendez 36 Register Mode Addressing Use % to denote register E.g., %eax Source operand: use value in specified register Destination operand: use register as destination for value Examples: movl %eax, %ebx Copy content of %eax to %ebx movl $0x4040, %eax ! immediate addressing Copy 0x4040 to %eax movl %eax, 0x0000f ! Absolute addressing Copy content of %eax to memory location 0x0000f 36
Image of page 36
Rutgers University David Menendez 37 Indirect Mode Addressing Content of operand is an address Designated as parenthesis around operand Offset can be specified as immediate mode Examples: movl (%ebp), %eax Copy value from memory location whose address is in ebp into eax movl -4(%ebp), %eax Copy value from memory location whose address is -4 away from content of ebp into eax
Image of page 37
Rutgers University David Menendez 38 Indexed Mode Addressing Add content of two registers to get address of operand movl (%ebp, %esi), %eax Copy value at (address = ebp + esi) into eax movl 8(%ebp, %esi),%eax Copy value at (address = 8 + ebp + esi) into eax Useful for dealing with arrays If you need to walk through the elements of an array Use one register to hold base address, one to hold index E.g., implement C array access in a for loop Index cannot be ESP 38
Image of page 38
Rutgers University David Menendez 39 Scaled Indexed Mode Addressing Multiply the second operand by the scale (1, 2, 4 or 8) movl 0x80 (%ebx, %esi, 4), %eax Copy value at (address = ebx + esi*4 + 0x80) into eax Where is it useful? 39
Image of page 39
40 Address Computation Examples %edx %ecx 0xf000 0x100 Expression Computation Address 0x8(%edx) 0xf000 + 0x8 0xf008 (%edx,%ecx) 0xf000 + 0x100 0xf100 (%edx,%ecx,4) 0xf000 + 4*0x100 0xf400 0x80(,%edx,2) 2*0xf000 + 0x80 0x1e080
Image of page 40
Rutgers University David Menendez 41 movl Operand Combinations Cannot do memory-memory transfers with single instruction movl Imm Reg Mem Reg Mem Reg Mem Reg Source Destination movl $0x4,%eax movl $-147,(%eax) movl %eax,%edx movl %eax,(%edx) movl (%eax),%edx C Analog temp = 0x4; *p = -147; temp2 = temp1; *p = temp; temp = *p;
Image of page 41
Rutgers University David Menendez 42 Stack Operations By convention, %esp is used to maintain a stack in memory Used to support C function calls %esp contains the address of top of stack
Image of page 42
Image of page 43

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture