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

The space macro makes the program do 2 spaces. The answer is 120__24__6__2__1. B

ID: 3734400 • Letter: T

Question

The space macro makes the program do 2 spaces. The answer is 120__24__6__2__1. But I'm not sure how you get there.

Can someone please explain step by step. I am confused.

36. (5 pts)The code below uses the Space macro defined previously. What output is generated by the MASM "program"? main PROC push 1 push 1 push 5 call rfinal exit main ENDP rfinal PROC push ebp mov ebp,esp mov eax, [ebp+16] mov ebx, [ebp+12] mov ecx, [ebp+8] mul ebx mov[ebp+16],eax cmp ebx , ecx jge unwind incebx push eax push ebx push ecx call rfinal unwlnd: eax, [ebp+16)] mov call WriteDec Space2 pop ebp ret 12 rfinal ENDP

Explanation / Answer

This assembly code is equivalent to following c code:

main(){

rfinal(1,1,5);

}

/* x=eax; start =ebx; end=ecx */

rfinal(int x, int start, int end){

int X, st, en;

X = x;

st = start;

en = end;

X = X*st;

if(st<en) {

st++;

rfinal(X,st,en);

}

printf(" %d", X);

}

}

Explanation:

1. x=1, start=1, end =5

X = X*st = 1

st++ => st =2

rfinal (1,2,5)

save print X => 1

2. x =1, start =2, end=5

X = X*st = 1*2 = 2

st++ => 3

rfinal(2,3,5)

save print X=>2

3. x=2, start=3,end=5

X = X*st= 2*3=6

st++ => 4

rfinal(6,4,5)

save print X => 6

4. x=6,start=4,end=5

X = X*st = 6*4 = 24

st++ => 5

rfinal(24,5,5)

save print X=>24

5. x=24, start=5,end=5

X = X*st = 24*5 = 120

if case false

print X => 120

Now all the prints will be executed in th reverse order: 120 24 6 2 1

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