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

Draw Stack of C Code? Consider the following C code fragment: and the following

ID: 3813938 • Letter: D

Question

Draw Stack of C Code?

Consider the following C code fragment:

and the following C function definition:

Example of stack going downwards:

Be as complete as possible, indicating values on the stack if known (e.g., “12”) or, if unknown, the name of the parameter/variable (e.g., “x = ?”). When indicating return addresses on the stack, whenever possible include the function returned to (e.g., “Return @ to f” as opposed to “Return @”). Assume that only the EBP register is saved by all the functions, and that the C calling convention is respected. You can assume that local variables are stored on the stack in the order in which they appear in the code (not in reverse order).

a -12 Saved EBP Return to h y E 12. Saved EBP 42 Return a to foo

Explanation / Answer

Below is the stack with variables values at different calls.

n=2 count = 10 width = 4 z=? y = 20 Saved EBP z=? n=( 5+2)7 count = 20 (y) width = (4-2)2 Saved EBP z=? y = (20*2)40 n = (7+5) 12 width = (2-2)0 Return @ to z z = -1 Saved EBP z = -13 (-1+(0*20-12) Return @ to g (-26 (2*-13))
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