我目前正在编写一个汇编程序来递归计算数字的阶乘。通过调试器,我看到了发生了什么。所以例如3阶乘。
public f ; make sure function name is exported
f:
push ebp ; push frame pointer
mov ebp, esp ; update ebp
push edi
mov ecx, [ebp+8] ; gettting my parameter at p0
mov edi, ecx ; making a copy
cmp edi, 1 ; check if n is greater than 0
jle finished
dec ecx ; subtrack 1 frm parameter
push ecx ; passing new value of n to parameter p0
mov eax, 0
call f
mul edi ; multiplying n * n-1
jmp finished2
finished:
mov eax, 1
finished2:
pop edi
mov esp, ebp
pop ebp
ret
所以可以说我有 3 作为我的输入,我应该有类似的东西
eax * 3(ecx)
eax * 2(ecx)
但我注意到在击中基本情况后返回的路上.. 值 2 放置在正确的位置,但值 3 永远不会进入正确的位置。