Question: Consider the following C program: 0 1 int f ( int n ) { 0 2 if ( n = = 1 ) 0 3

Consider the following C program:
01 int f(int n){
02 if(n ==1)
03 return 1; // this line
04 return n + f(n-1);
05}
06
07 int main(){
08 int result = f(5);
09 printf("The factorial of 5 is %d
", result);
10}
Suppose that the size of each stack frame for procedure f is 32 bytes. Also suppose that immediately before the call to f in main, %rsp contains 0x7fffffffdf70. Provide the contents of %rsp immediately before the commented line in f is executed.
%rsp contains 0x
.
(Assume a direct translation to x86 with no optimizations.)
Flag question: Question 3
Question 32 pts
Suppose that we have disassembled a program and see these two lines at the site of a procedure call:
...
0x4004f6: callq 0x40050c
0x4004fb: mov $0x0,%eax
...
Execution of the callq instruction causes address 0x
to be pushed onto the stack, and address 0x
to be placed in %rip.
Flag question: Question 4
Question 41 pts
The value of which argument is placed into register %rax to prepare for a procedure call?
Group of answer choices
1st argument
2nd argument
3rd argument
4th argument
5th argument
6th argument
none of the above
Flag question: Question 5
Question 51 pts
Where is the value of a potential 7th argument placed to prepare for a procedure call?
Group of answer choices
in register %rsi
in register %r9
in memory at the address (%rsp)
in memory at the address 8(%rsp)
in memory at the address -8(%rsp)
none of the above
Flag question: Question 6
Question 62 pts
Consider the following C program:
int p(int a, int b){
return q(b, a)+3a -2b;
}
int q(int x, int y){
return x + y;
}
int main(){
int result = p(1,2);
printf("The answer is %d
", result);
}
Notice that both p and q use the first two argument registers.
Who is responsible for saving the values of p's two arguments, to ensure that they are available for use after the call to q?
[ Select ]
Which x86 operation is used to save the contents of a register?
[ Select ]
Which x86 operation is used to restore the contents of a register?
[ Select ]
Flag question: Question 7
Question 71 pts
What is the exact compiler flag one can use with gcc so that helpful information (e.g., function names, line numbers) can be seen when debugging with gdb?
Flag question: Question 8
Question 82 pts
Match the x86 instruction to where it belongs in a procedure's prolog or epilog.
Group of answer choices
1st prolog instruction
[ Choose ]
2nd prolog instruction
[ Choose ]
1st epilog instruction
[ Choose ]
2nd epilog instruction
[ Choose ]

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 Finance Questions!