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

Exercise 3 The following PC18-C program performs the factorial\" operation using

ID: 3349199 • Letter: E

Question

Exercise 3 The following PC18-C program performs the factorial" operation using "recursive" function calls. Assume that the stack pointer originally has the value 0x900 when the program starts. Assume that you put a breakpoint at the instruction marked with SSSS, and look at the stack pointer (SP) register when the program breaks there. Choose the most likely correct answer below: (a) SP sll contains 0x900. (b) SP contains 0x8FD (i.e., slightly smaller than the original value) c) SP contains 0x903 (i.e, slightly larger than the original value) (d) SP contains Ox8EF (i.c., substantially smaller than the original value). (e) SP contains 0x914 (i.e., substantially larger than the original value) unsigned char fact (unsigned char n) if (n=#0 ) return 1; 1/ $$$Ssss I else return n fact (n-1) void main (void) unsigned char n, result; EnableInterrupts; n=5; result = fact (n); for (ai) loop forever /

Explanation / Answer

d) SP contains 0x8EF (i.e, substantially smaller than original value)

The system stores the return address (2 bytes) on to the stack each time the function "fact" is called upon. And also the function "fact" passes input parameter n into the stack. Since n=5, this is done 6 times. So, we have put 6 x 3 = 18 bytes into the stack. Thus, the SP is substantially smaller than the original value. So, the correct answer is d).