現在、数値の階乗を再帰的に計算するアセンブリ プログラムを作成しています。デバッガーを使用して、何が起こっているかを見てきました。たとえば、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は決して正しい場所に入りません。