- 论坛徽章:
- 0
|
本帖最后由 lazy_linux 于 2014-08-04 21:36 编辑
在gcc/config/i386/i386.h中定义了CALL_USED_REGS,文中中介绍说,如果call_used_regs\[i\] 等于0,
那么在进入函数时应先保存该寄存器i的值,在函数返回后要恢复该寄存器i的值。
我用gdb对编译出的编译器进行调试,有如下结果:
(gdb) print call_used_regs
$11 = "\001\001\001\000\000\000\000", '\001' <repeats 46 times>
这四个寄存器分别是bx, si, di, bp。
写了一个测试程序:
[GCC@localhost test]$ cat func_call.c
int f(){
return 1;
}
int main(int agrc, char *argv[]){
int i;
i = f();
return i;
}
但是在生成的汇编代码如下:
[GCC@localhost test]$ cat func_call.s
.file "func_call.c"
.text
.globl f
.type f, @function
f:
pushl %ebp
movl %esp, %ebp
movl $1, %eax
popl %ebp
ret
.size f, .-f
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
call f
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.4.0"
.section .note.GNU-stack,"",@progbits
函数f进入和退出时值保存和恢复了bp的值,其它的寄存器为什么没有处理呢?
是我对CALL_USED_REGS理解不对吗?
请斑竹和各位指点,谢谢!!
|
|