現在、組み立てで忙しく、次の問題に遭遇しました。
eax レジスタに入力された数値を取得しようとしています。最初に入力を求める文字列を提示し、次に誰かが数字を入力する必要があります。
次のコードを使用しましたが、すべてを理解していません。コード内のコメントに注意してください。
番号が eax に移動されたことを除いて、今では何も起こらないことはわかっています。私が知りたいのは、なぜlealを使わなければならないのかということです: なぜ、それは何をするのですか? そして、なぜ eax をスタックに戻す必要があるのですか?
.text
string1: .asciz "Please enter a number\n"
input: .asciz "%d"
.global main
main:
# Editor's note: this code is broken / unsafe; missing push %ebp here
movl %esp, %ebp
push $string1 # prompt string
call printf #print the string
# no add $4, %esp here: 4 bytes still allocated on the stack
leal -4(%ebp), %eax # ????
pushl %eax # the thing you pushed in eax is now pushed on the stack?
pushl $input #the number
call scanf
popl %eax
popl %eax # the number that has been entered is now in eax
call end
end:
push $0
call exit