c 代码调用汇编代码
汇编 world.asm
SECTION .TEXT
GLOBAL calc
calc:
mov rax,rdi
add rax,r9
ret
编译:
$ nasm -f elf64 world.asm -o world.o
C 代码:
#include <stdio.h>
int main(int argc, char *argv[]) {
extern int calc(int, int, int, int, int, int);
printf("%d\n", calc(1, 3, 5, 7, 9, 11));
return 0;
}
合在一块编译成目标文件 并执行
$ gcc hello.c world.o -o hello
$ ./hello
从 C 代码产生汇编代码:
gcc -S -Og test.c
汇编特殊指令:
.LC0 local constant, e.g string literal. .LFB0 local function beginning, .LFE0 local function ending,
源代码只预处理, 编译, 汇编, 链接
gcc -E -o hello.i hello.c gcc -S -o hello.s hello.c gcc -c -o hello.o hello.c gcc -o hello hello.c