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

The C function main() invokes the function cogito(), which invokes ergo() which

ID: 3698328 • Letter: T

Question


The C function main() invokes the function cogito(), which invokes ergo() which invokes sum(). Using the gdb debugger, the process is stopped in sum() on a 64-bit Intel machine.

The auto variable x in sum() is at -4(%rbp).

The auto variable y in ergo() is at -8(%rbp).

The auto variable z in cogito() is at -4(%rbp).

The current value in %rbp is 0x8840.

The contents of memory location 0x8840 is 0x8950.

The contents of memory location 0x8950 is 0x9230.

The contents of memory location 0x9230 is 0x9340.

a. What is the address of the auto variable x in sum()?

b. What is the address of the auto variable y in ergo()?

c. What is the address of the auto variable z in cogito()?

Explanation / Answer

a)

The auto variable x in the function sum() is at -4(%rbp) and the current value of %rbp is 0x8840
-4(%rbp) gives the current stack pointer location...
which is Memory address = [rbp - 4] ====> 0x8840 - 4 ==> 0x883c(Using hexa-decimal addition that is 0x8840+(-4).

Here, the two's complement of 4 is taken as it is negative and added to 0x8840)


b)

Similarly the address of the auto variable y in the function ergo() can be calculated. The auto variable y in ergo() is at -8(%rbp) and the current value of %rbp now is 0x8950.
Since, the current memory location of rbp is 0x8950
So, the address = [rbp - 8] ====> 0x8950 - 8 ==> 0x8948

c)

The auto variable x in the function cogito() is at -4(%rbp) and the current value of %rbp is 0x9230.

The current memory location of rbp is 0x9230
So, the address = [rbp - 4] ====> 0x9230 - 4 ==> 0x922c

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