main函数的在调用其他函数前栈帧的困惑
学习深入理解计算机系统有关汇编那章,产生疑惑...int main() {
int a[11] = {49,38,65,97,26,13,27,49,55,4,5};
insertsort(a, 11);
}
反汇编代码如下:(call insertsort以后都省去了)
080484da <main>:
80484da: 8d 4c 24 04 lea 0x4(%esp),%ecx
80484de: 83 e4 f0 and $0xfffffff0,%esp
80484e1: ff 71 fc pushl -0x4(%ecx)
80484e4: 55 push %ebp
80484e5: 89 e5 mov %esp,%ebp
80484e7: 51 push %ecx
80484e8: 83 ec 34 sub $0x34,%esp
80484eb: 65 a1 14 00 00 00 mov %gs:0x14,%eax
80484f1: 89 45 f4 mov %eax,-0xc(%ebp)
80484f4: 31 c0 xor %eax,%eax
80484f6: c7 45 c8 31 00 00 00 movl $0x31,-0x38(%ebp)
80484fd: c7 45 cc 26 00 00 00 movl $0x26,-0x34(%ebp)
8048504: c7 45 d0 41 00 00 00 movl $0x41,-0x30(%ebp)
804850b: c7 45 d4 61 00 00 00 movl $0x61,-0x2c(%ebp)
8048512: c7 45 d8 1a 00 00 00 movl $0x1a,-0x28(%ebp)
8048519: c7 45 dc 0d 00 00 00 movl $0xd,-0x24(%ebp)
8048520: c7 45 e0 1b 00 00 00 movl $0x1b,-0x20(%ebp)
8048527: c7 45 e4 31 00 00 00 movl $0x31,-0x1c(%ebp)
804852e: c7 45 e8 37 00 00 00 movl $0x37,-0x18(%ebp)
8048535: c7 45 ec 04 00 00 00 movl $0x4,-0x14(%ebp)
804853c: c7 45 f0 05 00 00 00 movl $0x5,-0x10(%ebp)
8048543: 6a 0b push $0xb
8048545: 8d 45 c8 lea -0x38(%ebp),%eax
8048548: 50 push %eax
8048549: e8 ed fe ff ff call 804843b <insertsort>
以下是我写的main栈帧,不知对不对。
问题1:保存的%ecx和金丝雀上面的是什么?
问题2: 这栈帧在调用函数前保证了16个字节对齐了么?
问题3: 与上述代码无关:
call 804846b <BinarySearch>
add $0xc,%esp
sub $0x8,%esp
push %eax
push $0x8048610
call 8048330 <printf@plt>
同样在main函数里调用两个函数,但调用printf前比前一个函数时栈帧多了4个字节,保证了对齐了么?
可能有点长,麻烦了