Here is the code In question:
push 5
call Factorial
When I call this from main like this:
main PROC
push 5
call Factorial
exit
main ENDP
My code works fine, But if I call this as:
main PROC
call Binomial
exit
main ENDP
Binomial PROC
push 5
call Factorial
Binomial ENDP
I get a stack overflow at push eax
in the code below:
Factorial PROC
push ebp
mov ebp,esp
mov eax,[ebp+8]
cmp eax,0
ja L1
mov eax,1
jmp L2
L1:
dec eax
push eax
call Factorial
ReturnFact:
mov ebx,[ebp+8]
mul ebx
L2:
pop ebp
ret 4
Factorial ENDP
I can not figure out why, but when I call it from main, the Factorial procedure exits as it should and returns to main, but when it is called from Binomial, instead of returning back to Binomial, it goes back to Factorial...which I find very odd. Am I doing something wrong here?