Answer n Register eax set to op at beginning of procedure n This becomes the

Answer n register eax set to op at beginning of

This preview shows page 84 - 95 out of 126 pages.

Answer n Register %eax set to op at beginning of procedure n This becomes the returned value Advantage of Jump Table n Can do k -way branch in O (1) operations .L49: # Done: movl %ebp,%esp # Finish popl %ebp # Finish ret # Finish
Image of page 84
Rutgers University Santosh Nagarakatte 85 IA32 Stack n Region of memory managed with stack discipline n Grows toward lower addresses n Register %esp indicates lowest stack address l address of top element Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom”
Image of page 85
Rutgers University Santosh Nagarakatte 86 IA32 Stack Pushing Pushing n pushl Src n Fetch operand at Src n Decrement %esp by 4 n Write operand at address given by %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” Stack Pointer %esp -4
Image of page 86
Rutgers University Santosh Nagarakatte 87 IA32 Stack Popping Popping n popl Dest n Read operand at address given by %esp n Increment %esp by 4 n Write to Dest Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” +4
Image of page 87
%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 88
Rutgers University Santosh Nagarakatte 89 Procedure Control Flow n Use stack to support procedure call and return Procedure call: call label Push return address on stack; Jump to label Return address value n Address of instruction beyond call n Example from disassembly 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax l Return address = 0x8048553 Procedure return: n ret Pop address from stack; Jump to address
Image of page 89
%esp %eip %esp %eip 0x804854e 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 90
%esp %eip 0x104 %esp %eip 0x8048591 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 91
Rutgers University Santosh Nagarakatte 92 Stack-Based Languages Languages that Support Recursion n e.g., C, Pascal, Java n Code must be “ Reentrant l Multiple simultaneous instantiations of single procedure n Need some place to store state of each instantiation l Arguments, local variables, return pointer Stack Discipline n State for given procedure needed for limited time l From when called to when return n Callee returns before caller does Stack Allocated in Frames (Activation records) n state for single procedure instantiation
Image of page 92
Rutgers University Santosh Nagarakatte 93 Call Chain Example Code Structure yoo(…) { who(); } who(…) { • • • amI(); • • • amI(); • • • } amI(…) { amI(); } yoo who amI amI amI Call Chain n Procedure amI recursive amI
Image of page 93
Rutgers University Santosh Nagarakatte 94 Stack Pointer %esp yoo who proc Frame Pointer %ebp Stack “Top” Stack Frames Contents n Local variables, return value n Temporary space Management n Space allocated when enter procedure l “Set-up” code n Deallocated when return l “Finish” code Pointers n Stack pointer %esp : stack top n Frame pointer %ebp : start of current frame amI
Image of page 94
Image of page 95

You've reached the end of your free preview.

Want to read all 126 pages?

  • Spring '08
  • Chakraborty
  • X86, Processor register, Rutgers University, Addressing mode, eax, Prof. Santosh Nagarakatte

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture