Question: Amelia really likes recursive functions and has written a function fun_times that produces the following assembly code when compiled using GCC: --------------------------------------------------------------------------- fun_times: pushq %rbp
Amelia really likes recursive functions and has written a function fun_times that produces the following assembly code when compiled using GCC:
--------------------------------------------------------------------------- fun_times: pushq %rbp movq %rsp, %rbp subq $32, %rsp movq %rdi, -24(%rbp) movl %esi, -28(%rbp) cmpl $0, -28(%rbp) jne .L2 movl $0, %eax jmp .L3 .L2: movl $0, -4(%rbp) jmp .L4 .L5: movl -4(%rbp), %eax movslq %eax, %rdx movq -24(%rbp), %rax addq %rdx, %rax movzbl (%rax), %eax movsbl %al, %eax addl %eax, -8(%rbp) addl $1, -4(%rbp) .L4: movl -4(%rbp), %eax cmpl -28(%rbp), %eax jl .L5 movl -28(%rbp), %eax leal -1(%rax), %edx movq -24(%rbp), %rax movl %edx, %esi movq %rax, %rdi call fun_times movl %eax, %edx movl -8(%rbp), %eax addl %edx, %eax .L3: leave ret
A. What does fun_times do? Demonstrate the logic either in C code or in pseudocode.
B. How many bytes is allocated on the stack with each call to fun_times? C. Where is the result (i.e., return value) stored?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
