実際に使用できるメモリポイントはどれですか? 私は電源に、このアセンブリコードを持っている(a、b)は再帰によって:アセンブリーint x86のアドレスを使用して引数を定義することができます
int power(int x, int y); *
;*****************************************************************************
%define x [ebp+8]
%define y [ebp+12]
power:
push ebp
mov ebp, esp
mov eax, y ;move y into eax
cmp eax, 0 ;compare y to 0
jne l10; ;if not equal, jump to l10
mov eax, 1 ;move 1 into eax
jmp l20; ;jump to l20, the leave, ret label
l10:
mov eax, y ; move y into eax
sub eax, 1 ; y-1
push eax ; push y-1 onto stack
mov ebx, x ; move x into ebx
push ebx ; push x onto stack
call power ; call power/recursion
add esp, 8 ; add 8 to stack(4*2) for the two vars
imul eax, x ; multiply the returned value from call by x
l20:
leave ; leave
ret ;ret
それは、このCコードから直接コード化されています:ASMコードは完璧に動作
int power_c(int x, int y) {
if (y == 0) {
return 1;
} else {
return power_c(x, y - 1)*x;
}
}
、任意の提案の調整は素晴らしいことです、私はまだ組み立てに新しいです。私の質問は、私は実際に引数を定義するためにどのアドレスを使用できますか?ここでは2つありますが、私は次のように使います:
%define x [ebp+8]
%define y [ebp+12]
もし私がもっと持っていたら、それを増やすだけですか?すべてがint、4bytesなのでそうですか?
%define x [ebp+8]
%define y [ebp+12]
%define z [ebp+16]
%define a [ebp+20]
%define b [ebp+24]
私はより多くの引数を定義する必要があるコードで暗礁に乗り上げるてきた、私はちょうどこれを理解することはできません、任意の助けをいただければ幸いです。
xとyは関数の引数であり、ローカル変数ではありません。彼らは異なった扱いを受ける。 – AShelly
参照してください。私は彼らが違っているとは決して考えなかった。これを明確にしていただきありがとうございます。 – Monkleys
@AShellyこちら、https://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Framesで説明しました。問題の変更、チェックを編集します。 – Monkleys