Assembly language practice question help A Write a MASM macr

Assembly language practice question help!!!

A. Write a MASM macro named Factorial that calculates x! (x factorial) for its parameter x, and stores the
result in memory at the second parameter. The caller passes x by value, and the result variable by
address. Make sure to preserve/restore used registers, and remember to use LOCAL labels only.

b. Invoke the macro of part A) to calculate 9!, and save the result to result.

Solution

.code
push N
call fact
push edi
push offset format
push offset buffer
call _imp__wsprintfA
add esp,12
push 0
push offset caption
push offset buffer
push 0
call _imp__MessageBoxA@16
ret

fact proc
mov ecx,[esp+4]
jecxz done

dec ecx
push ecx

call fact
mov eax,edi

mul dword ptr [esp+4]

jmp short rtrn
done: mov eax,1

rtrn: mov edi,eax

retn 4


fact endp
.data
format db \'result=%lu\',0
buffer db 50 dup (0)
caption db \' result‘,0

Assembly language practice question help!!! A. Write a MASM macro named Factorial that calculates x! (x factorial) for its parameter x, and stores the result in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site