Question: 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

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 return 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? (be sure to

exaplain your answer). Recall the jg instruction jumps if the result is greater than 0. (20

points, 5 points each for a-d)

Foo:

pushq %rbp

movq %rsp, %rbp

subq $16, %rsp

movl %edi, -4(%rbp)

movq %rsi, -16(%rbp)

cmpl $1, -4(%rbp)

jg .L2

movl $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

addq %rdx, %rax

addq %rax, -16(%rbp)

movq -16(%rbp), %rax

.L3:

leave

ret

(gdb) x/30x $rsp 0x7fffffffe780: 0x00007fffffffe848 0x0000000000000400 0x7fffffffe790: 0x00007fffffffe7b0 0x00000000004005d3 0x7fffffffe7a0: 0x0000000000000000 0x00000002f7de8c95 0x7fffffffe7b0: 0x00007fffffffe7d0 0x00000000004005d3 0x7fffffffe7c0: 0x0000000000000000 0x00000004f7a17190 0x7fffffffe7d0: 0x00007fffffffe7f0 0x00000000004005d3 0x7fffffffe7e0: 0x0000000000000000 0x00000006f7def725 0x7fffffffe7f0: 0x00007fffffffe810 0x00000000004005d3 0x7fffffffe800: 0x0000000000000002 0x00000008ffffe844 0x7fffffffe810: 0x00007fffffffe830 0x00000000004005d3 0x7fffffffe820: 0x000000000000000a 0x0000000a00000000 0x7fffffffe830: 0x00007fffffffe850 0x000000000040062a 0x7fffffffe840: 0x0000000affffe930 0x000000000000000a 0x7fffffffe850: 0x0000000000000000 0x00007ffff7a32ea5 0x7fffffffe860: 0x0000000000000000 0x00007fffffffe938

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!