Eaxedx mem movl eaxedx vard vara mem movl reg

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s have special uses for parIcular instrucIons   Memory: 4 consecuIve bytes of memory at address given by register   Simplest example: (%eax)   Various other “address modes”   x86 University of Washington movl Operand CombinaMons Source Dest Src,Dest C Analog Imm var_a = 0x4; Reg Reg movl %eax,%edx Mem movl %eax,(%edx) var_d = var_a; Mem movl Reg movl $0x4,%eax Mem movl $-147,(%eax) Reg var_d = *p_a; movl (%eax),%edx *p_a = -147; *p_d = var_a; Cannot do memory ­memory transfer with a single instruc<on. x86 University of Washington Memory Addressing Modes: Basic     Indirect (R) Mem[Reg[R]]   Register R specifies the memory address movl (%ecx),%eax Displacement D(R) Mem[Reg[R]+D]   Register R specifies a memory address   (e.g. the start of some memory region)   Constant displacement D specifies the offset from that address movl 8(%ebp),%edx x86 University of Washington Using Basic Addressing Modes void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl movl movl movl movl movl 12(%ebp),%ecx 8(%ebp),%edx (%ecx),%eax (%edx),%ebx %eax,(%edx) %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret x86 Set Up Body Finish University of Washington Understanding Swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } • • • Offset 12 yp 8 xp 4 Stack (in memory) Rtn adr 0 Old %ebp Register %ecx %edx %eax %ebx Value yp xp t1 t0 %ebp -4 Old %ebx movl movl movl movl movl movl 12(%ebp),%ecx 8(%ebp),%edx (%ecx),%eax (%edx),%ebx %eax,(%edx) %ebx,(%ecx) x86 # # # # # # ecx edx eax ebx *xp *yp = = = = = = yp xp *yp (t1) *xp (t0) eax ebx University of Washington 123 456 Understanding Swap Address 0x124 0x120 0x11c %eax Offset %edx 0x114 yp %esi 0x120 0x110 8 0x124 0x10c 4 %ebx 12 xp %ecx Rtn adr 0x108 0 %ebp %edi 0x104 -4 %esp %ebp 0x118 0x104 movl movl movl movl movl movl 12(%ebp),%ecx 8(%ebp),%edx (%ecx),%eax (%edx),%ebx %eax,(%edx) %ebx,(%ecx) x86 # # # # # # ecx edx eax ebx *xp *yp 0x100 = = = = = = yp xp *yp (t1) *xp (t0) eax ebx University of Washington 123 456 Understanding Swap Address 0x124 0x120 0x11c %eax Offset %edx 0x114 yp %esi 0x120 0x120 0x110 8 0x124 0x10c 4 %ebx 12 xp %ecx 0x120 Rtn adr 0x...
View Full Document

Ask a homework question - tutors are online