vscode实现。
1、编写简单C语言程序hello.c:
#include int main(){int i=0;printf("%d\n",i);return 0;}
2、生成汇编文件:
终端输入gcc -S hello.c 就会生成hello.s
可添加asm插件,使汇编代码有颜色便于阅读。
.section__TEXT,__text,regular,pure_instructions.build_version macos, 10, 15sdk_version 10, 15, 6.globl_main ## -- Begin function main.p2align4, 0x90_main:## @main.cfi_startproc## %bb.0:pushq%rbp.cfi_def_cfa_offset 16.cfi_offset %rbp, -16movq%rsp, %rbp.cfi_def_cfa_register %rbpsubq$16, %rspmovl$0, -4(%rbp)movl$0, -8(%rbp)movl-8(%rbp), %esileaqL_.str(%rip), %rdimovb$0, %alcallq_printfxorl%ecx, %ecxmovl%eax, -12(%rbp) ## 4-byte Spillmovl%ecx, %eaxaddq$16, %rsppopq%rbpretq.cfi_endproc## -- End function.section__TEXT,__cstring,cstring_literalsL_.str: ## @.str.asciz"%d\n".subsections_via_symbols
3、生成二进制目标文件hello.o
终端输入gcc -c hello.c
4、生成二进制可执行文件prog
终端输入gcc -o prog hello.c sum.c
5、反汇编
终端输入objdump -d hello.o
hello.o:file format Mach-O 64-bit x86-64Disassembly of section __TEXT,__text:0000000000000000 _main: 0: 55pushq %rbp 1: 48 89 e5movq%rsp, %rbp 4: 48 83 ec 10 subq$16, %rsp 8: c7 45 fc 00 00 00 00movl$0, -4(%rbp) f: c7 45 f8 00 00 00 00movl$0, -8(%rbp)16: 8b 75 f8movl-8(%rbp), %esi19: 48 8d 3d 14 00 00 00leaq20(%rip), %rdi20: b0 00 movb$0, %al22: e8 00 00 00 00callq 0 27: 31 c9 xorl%ecx, %ecx29: 89 45 f4movl%eax, -12(%rbp)2c: 89 c8 movl%ecx, %eax2e: 48 83 c4 10 addq$16, %rsp32: 5dpopq%rbp33: c3retq