Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. You know the following assembly code snippet is from a recursive function in

ID: 3870685 • Letter: 7

Question

7. You know the following assembly code snippet is from a recursive function in C. you also know that the stack contents at a particular point in time when we are in the recursive function are shown on the next page. Answer the following questions: a) how many Foo stack frames are on the stack? b) what is the retum address back to the function that called Foo for the first time? c) what is the return address back into the function Foo? d) how many bytes is in one instance of the Foo stack frame? (b exaplain your answer). Recall the ig instruction jumps if the result is greater than points, 5 points each for a-d) e sure to Foo: %rbp %rsp, %rbp pushq movq subq $16, %rsp movl %edi,-4(%rbp) movq %rsi,-16(%rbp) crmpl $1,-4(%rbp) ig .L2 movi $10, %eax jmp L3 ·L2: movq -16(%rbp), %rax movq %rax,%rdx sarq $2, %rdx movl -4(%rbp), %eax subl $2, %eax movq %rdx, %rsi movl %eax, %edi call Foo movq -16(%rbp), %rdx sarq $2, %rdx %rdx, %rax ‰ax,-16(%rbp) -16(%rbp), %rax addq addq movq ·L3: leave

Explanation / Answer

a) One frame: There is only one jump from 0x7fffffffe790 to 0x7fffffffe7a0

b) Foo() was called from 0x7fffffffe790 in the L2 so the return address is 0x7fffffffe790.

c) 0x7fffffffe7f0 is where Foo() makes a jump to L2 thus return address is 0x7fffffffe7f0.

d) Foo() stack frame is from 0x7fffffffe7a0 to 0x7fffffffe7f0 => 12bytes (each instruction is taking two bytes and there are 6 in the frame)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote