|
|
c程序转化为汇编后该怎么汇编呢?
我的作法如下:
这是我的c程序
- /* t.c */
- #include <stdio.h>
- int f(int a)
- {
- return a++;
- }
- int main()
- {
- int v = 1;
- f(v);
- return 0;
- }
复制代码
# gcc -S -O3 t.c后结果如下
- .file "t.c"
- .text
- .p2align 4,,15
- .globl f
- .type f, @function
- f:
- pushl %ebp
- movl %esp, %ebp
- movl 8(%ebp), %eax
- popl %ebp
- ret
- .size f, .-f
- .p2align 4,,15
- .globl main
- .type main, @function
- main:
- pushl %ebp
- xorl %eax, %eax
- movl %esp, %ebp
- subl $8, %esp
- andl $-16, %esp
- subl $16, %esp
- leave
- ret
- .size main, .-main
- .ident "GCC: (GNU) 4.0.0 (Gentoo Linux 4.0.0)"
- .section .note.GNU-stack,"",@progbits
复制代码
链接的时候出了点问题
- [leo@leo test]$ as t.s -o t.o
- [leo@leo test]$ ld -dynamic-linker /lib/ld-linux.so.2 -o a.out t.o
- ld: warning: cannot find entry symbol _start; defaulting to 00000000080480c0
复制代码
我于是在.text后加了两句
这样链接就没有warning了,但运行程序时会出现Segmentation fault,不知道什么原因
btw 用gdb调试汇编程序可以查看寄存器的值么? |
|