Simple memory addressing modes normal r memregr

Info icon This preview shows pages 21–32. Sign up to view the full content.

View Full Document Right Arrow Icon
Simple Memory Addressing Modes Normal (R) Mem[Reg[R]] Register R specifies memory address Aha! Pointer dereferencing in C movq (%rcx),%rax Displacement D(R) Mem[Reg[R]+D] Register R specifies start of memory region Constant displacement D specifies offset movq 8(%rbp),%rdx
Image of page 21

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

View Full Document Right Arrow Icon
Carnegie Mellon 22 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Example of Simple Addressing Modes whatAmI: movq (%rdi), %rax movq (%rsi), %rdx movq %rdx, (%rdi) movq %rax, (%rsi) ret void whatAmI(<type> a, <type> b) { ???? } %rdi %rsi
Image of page 22
Carnegie Mellon 23 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Example of Simple Addressing Modes void swap (long *xp, long *yp) { long t0 = *xp; long t1 = *yp; *xp = t1; *yp = t0; } swap: movq (%rdi), %rax movq (%rsi), %rdx movq %rdx, (%rdi) movq %rax, (%rsi) ret
Image of page 23

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

View Full Document Right Arrow Icon
Carnegie Mellon 24 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition %rdi %rsi %rax %rdx Understanding Swap () void swap (long *xp, long *yp) { long t0 = *xp; long t1 = *yp; *xp = t1; *yp = t0; } Memory Register Value %rdi xp %rsi yp %rax t0 %rdx t1 swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret Registers
Image of page 24
Carnegie Mellon 25 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Understanding Swap () 123 456 %rdi %rsi %rax %rdx 0x120 0x100 Registers Memory swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret 0x120 0x118 0x110 0x108 0x100 Address
Image of page 25

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

View Full Document Right Arrow Icon
Carnegie Mellon 26 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Understanding Swap () 123 456 %rdi %rsi %rax %rdx 0x120 0x100 123 Registers Memory swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret 0x120 0x118 0x110 0x108 0x100 Address
Image of page 26
Carnegie Mellon 27 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Understanding Swap () 123 456 %rdi %rsi %rax %rdx 0x120 0x100 123 456 Registers Memory swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret 0x120 0x118 0x110 0x108 0x100 Address
Image of page 27

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

View Full Document Right Arrow Icon
Carnegie Mellon 28 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Understanding Swap () 456 456 %rdi %rsi %rax %rdx 0x120 0x100 123 456 Registers Memory swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret 0x120 0x118 0x110 0x108 0x100 Address
Image of page 28
Carnegie Mellon 29 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Understanding Swap () 456 123 %rdi %rsi %rax %rdx 0x120 0x100 123 456 Registers Memory swap: movq (%rdi), %rax # t0 = *xp movq (%rsi), %rdx # t1 = *yp movq %rdx, (%rdi) # *xp = t1 movq %rax, (%rsi) # *yp = t0 ret 0x120 0x118 0x110 0x108 0x100 Address
Image of page 29

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

View Full Document Right Arrow Icon
Carnegie Mellon 30 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Simple Memory Addressing Modes Normal (R) Mem[Reg[R]] Register R specifies memory address Aha! Pointer dereferencing in C movq (%rcx),%rax Displacement D(R) Mem[Reg[R]+D] Register R specifies start of memory region Constant displacement D specifies offset movq 8(%rbp),%rdx
Image of page 30
Carnegie Mellon 31 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Complete Memory Addressing Modes Most General Form D(Rb,Ri,S) Mem[Reg[Rb]+S*Reg[Ri]+ D]
Image of page 31

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

View Full Document Right Arrow Icon
Image of page 32
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '10
  • DaveO