今天使用nasm和gcc一起编译了一个程序
先使用nasm编译一个asm文件为elf格式,汇编文件里面有全局global的_start和functionC,将来连接的时候用。其中还有extern用来表示外部C语言中的函数。
我的程序的调用结构: _start(ASM)->funB(C)->funC(ASM)
其中 ASM文件中:extern funB、global _start、global funC
C文件中声明:void funC();
函数参数的传递:使用push来传递地址 ,而不是数值。最后参数的清理需要caller来自己解决。
需要的命令行:
nasm -f elf -o dest .o src .asm
gcc -c -o dest2 .o src2 .c (-c 的意思是仅仅compile)
ld -s -o final .o dest .o dest1 .o