C编译汇编

源码:
`#include <stdio.h>

int main(void) {
printf("Hello, World! \n");
return 0;
}`

生成32位汇编,报错,需要装库

[root@cdh1 c_demo]# gcc -m32 -S demo.c
In file included from /usr/include/features.h:399:0,
from /usr/include/stdio.h:27,
from demo.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

include <gnu/stubs-32.h>

                       ^

解决:yum -y install glibc-devel.i686

gcc -S 会直接生成64位的汇编
我们研究32位的:
生成demo.s---就是汇编代码片段

.file "demo.c" .section .rodata .LC0: .string "Hello, World! " .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts movl $0, %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-4)" .section .note.GNU-stack,"",@progbits

posted @ 2023-01-01 20:57  长江大河  阅读(5)  评论(0)    收藏  举报