First xp in rdi and yp in rsi 64 bit pointers data values are 32 bit ints so

First xp in rdi and yp in rsi 64 bit pointers data

This preview shows page 53 - 66 out of 160 pages.

First, xp in rdi and yp in rsi 64-bit pointers, data values are 32-bit ints, so uses eax/edx No stack operations What happens with long int?
Image of page 53
Rutgers University David Menendez 54 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Register %esp indicates lowest stack address address of top element Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom”
Image of page 54
Rutgers University David Menendez 55 IA32 Stack Pushing Pushing pushl Src Fetch operand at Src Decrement %esp by 4 Write operand at address given by %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” Stack Pointer %esp -4
Image of page 55
Rutgers University David Menendez 56 IA32 Stack Popping Popping popl Dest Read operand at address given by %esp Increment %esp by 4 Write to Dest Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” +4
Image of page 56
%esp %eax %edx %esp %eax %edx %esp %eax %edx 0x104 0x108 0x10c 0x110 0x104 555 213 213 123 Stack Operation Examples 0x108 0x10c 0x110 555 213 123 0x108 0x104 pushl %eax 0x108 0x10c 0x110 213 123 213 popl %edx 0x108 213
Image of page 57
Rutgers University David Menendez 58 Procedure Control Flow Use stack to support procedure call and return Procedure call: call label Push return address on stack; Jump to label Return address value Address of instruction beyond call Example from disassembly 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax Return address = 0x8048553 Procedure return: ret Pop address from stack; Jump to address
Image of page 58
%esp %eip %esp %eip 0x108 0x10c 0x110 0x104 0x804854e 0x8048553 123 Procedure Call Example 0x108 0x10c 0x110 123 0x108 call 8048b90 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax 0x8048b90 0x104 %eip is program counter
Image of page 59
%esp %eip 0x104 %esp %eip 0x8048591 0x104 0x108 0x10c 0x110 0x8048553 123 Procedure Return Example 0x108 0x10c 0x110 123 ret 8048591: c3 ret 0x108 %eip is program counter 0x8048553 0x8048553
Image of page 60
Rutgers University David Menendez 61 Address Computation Instruction leal: compute address using addressing mode without accessing memory leal src, dest src is address mode expression Set dest to address specified by src Use Computing address without doing memory reference E.g., translation of p = &x[i]; Example: leal 7(%edx, %edx, 4), %eax eax = 4*edx + edx + 7 = 5*edx + 7
Image of page 61
Rutgers University David Menendez 62 Some Arithmetic Operations Instruction Computation addl Src , Dest Dest = Dest + Src subl Src , Dest Dest = Dest - Src imull Src , Dest Dest = Dest * Src sall Src , Dest Dest = Dest << Src (left shift) sarl Src , Dest Dest = Dest >> Src (right shift) xorl Src , Dest Dest = Dest ^ Src andl Src , Dest Dest = Dest & Src orl Src , Dest Dest = Dest | Src
Image of page 62
Rutgers University David Menendez 63 Some Arithmetic Operations Instruction Computation incl Dest Dest = Dest + 1 decl Dest Dest = Dest - 1 negl Dest Dest = - Dest notl Dest Dest = ~ Dest
Image of page 63
Using leal for Arithmetic Expressions int arith (int x, int y, int z) { int t1 = x+y; int t2 = z+t1; int t3 = x+4; int t4 = y * 48; int t5 = t3 + t4; int rval = t2 * t5; return rval; } arith: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax movl 12(%ebp),%edx leal (%edx,%eax),%ecx leal (%edx,%edx,2),%edx sall $4,%edx addl 16(%ebp),%ecx leal 4(%edx,%eax),%eax imull %ecx,%eax movl %ebp,%esp popl %ebp ret Body Set Up Finish
Image of page 64
Understanding arith int arith (int x, int y, int z) { int t1 = x+y; int t2 = z+t1;
Image of page 65
Image of page 66

You've reached the end of your free preview.

Want to read all 160 pages?

  • Fall '15
  • SantoshNagarakatte
  • Computer Architecture, X86, Processor register, Call stack, Rutgers University, Addressing mode, Prof. David Menendez

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture