Note that factorial(n-1)
will overwrite factorial(n)'s
value of EBX
the first thing it does, thereby rendering the inc EBX
after the push
pointless. After you've reached the base case you'll have the situation where EBX
is 0 when you do the mul
, and of course anything * 0 == 0.
The easiest fix would be to change the prologue to:
push EBP ; Retrieve parameter and put it
push EBX ; save previous param
mov EBP,ESP ; into EBX register
add EBP,12 ;
mov EBX,[EBP] ; EBX = Param
And the epilogue to:
pop EBX ; restore previous param
pop EBP ; Release EBP
ret