我正在通过比较一个c程序和它的程序集等价来学习程序集。程序集“mov”指令
这是代码。
.file "ex3.c"
.section .rodata
.LC0:
.string "I am %d years old.\n"
.LC1:
.string "I am %d inches tall.\n"
.text
.globl main
.type main, @function
main:
pushl %ebp //establish stack frame//
movl %esp, %ebp //move esp into ebp, all contents saved down stack//
andl $-16, %esp //16 from esp for local var space//
subl $32, %esp//stack frame reserving - 32 bytes//
movl $10, 24(%esp)
movl $72, 28(%esp)
movl 24(%esp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl 28(%esp), %eax
movl %eax, 4(%esp)
movl $.LC1, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2"
.section .note.GNU-stack,"",@progbits
对于此行:
movl $10, 24(%esp)
如果我没有理解它正确跟它移动值为10到ESP寄存器。但是24是干什么的?我不认为它移入ESP,因为要移动的“$”(我认为)
“将10的值移入esp寄存器” - 不。 esp周围的括号表示间接。 24是位移,又名偏移量。 –
在Intel语法中,它会更容易理解:'mov dword ptr [esp + 24],10' –