Question: Hi , i need to Draw the stack frames for these two assembly program First one : TITLE Calculating a Factorial (Fact.asm) ; This program
Hi , i need to Draw the stack frames for these two assembly program
First one :
TITLE Calculating a Factorial (Fact.asm)
; This program uses recursion to calculate the
; Factorial of an integer.
INCLUDE Irvine32.inc .data Msg BYTE "Enter an integer [n]: ",0
n BYTE ": is the current value of n-1",0
.code
main PROC
mov edx,OFFSET msg
call WriteString
call ReadDec push eax
call Factorial ; calculate factorial (eax)
call WriteDec ; display it
call Crlf exit
main ENDP
Factorial PROC
push ebp
mov ebp,esp
mov eax,[ebp+8] ; get n
cmp eax,0 ; n < 0? ja L1 ; yes: continue mov eax,1 ; no: return 1 jmp L2
L1: dec eax
Push eax ; Factorial(n-1) call WriteDec mov edx,OFFSET n
call WriteString
call Crlf call Factorial
; Instructions from this point on execute when each
; Recursive call returns.
mov ebx,[ebp+8] ; get n
mul ebx ; ax = ax * bx
L2: pop ebp ; return EAX
ret 4 ; clean up stack
Factorial ENDP
END main
Secound one :
TITLE Fill 2D Arrays
INCLUDE Irvine32.inc
.data
Msg BYTE"Enter an integer [n]: ",0
n BYTE":is the current value of n-1",0
.code
main PROC
mov edx,OFFSET msg
call WriteString
call ReadDec
push eax
call sum
call WriteDec
call Crlf
exit
main ENDP
sum PROC
push ebp
mov ebp,esp
mov eax,[ebp+8]
cmp eax,0
ja L1
mov eax,0
jmp L2
L1:
dec eax
Push eax
call WriteDec
mov edx,OFFSET n
call WriteString
call Crlf
call sum
mov ebx,[ebp+8]
add eax ,ebx
L2:
pop ebp
ret 4
sum ENDP
END main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
