executing assembly within a function in c++
问题 long getesp() { __asm__("movl %esp,%eax"); } void main() { printf("%08X\n",getesp()+4); } why does esp points to value before the stack frame is setup and does it makes any difference between with the code below? void main() { __asm__("movl %esp,%eax"); } 回答1: After i did a gcc -S file.c getesp: pushl %ebp movl %esp, %ebp subl $4, %esp #APP # 4 "xxt.c" 1 movl %esp,%eax # 0 "" 2 #NO_APP leave ret main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl