zne*_*eak 6 x86 assembly gnu-assembler
我决定在暑假期间学习x86组装会很有趣.所以我从一个非常简单的hello world程序开始,借用免费的例子gcc -S可以给我.我最终得到了这个:
HELLO:
.ascii "Hello, world!\12\0"
.text
.globl _main
_main:
pushl %ebp # 1. puts the base stack address on the stack
movl %esp, %ebp # 2. puts the base stack address in the stack address register
subl $20, %esp # 3. ???
pushl $HELLO # 4. push HELLO's address on the stack
call _puts # 5. call puts
xorl %eax, %eax # 6. zero %eax, probably not necessary since we didn't do anything with it
leave # 7. clean up
ret # 8. return
# PROFIT!
Run Code Online (Sandbox Code Playgroud)
它编译甚至工作!而且我认为我理解其中的大部分内容.
虽然,魔法发生在第3步.我是否会删除此行,我的程序将在调用puts和xor来自未对齐的堆栈错误之间死亡.我会改变$20另一个值,它也会崩溃.所以我得出结论,这个价值很very重要.
问题是,我不知道它的作用以及为什么需要它.
有人能解释一下吗?(我在Mac OS上,它会不会重要.)