c函数
#include <stdio.h>
int maxofthree(int, int, int);
int main(){
printf("%d\n",maxofthree(1,-4,7));
return 0;
}
nasm汇编文件
global maxofthree
section .text
maxofthree:
mov eax, [esp+4]
mov ecx, [esp+8]
mov edx, [esp+12]
label_2:
cmp eax, ecx
cmovl eax, ecx
cmp eax, edx
cmovl eax, edx
ret
链接生成可执行文件:
nasm -f elf -o func.o func.asm
gcc -c -o main.o main.c
ld -o hello main.o func.o
报错printf函数未定义
修改:
nasm -f elf -o func.o func.asm
gcc -o hello main.c func.o
报错
i386 architecture of input file `func.o' is incompatible with i386:x86-64 output 修改: nasm -f elf -o func.o func.asm gcc -m32 -o hello main.c func.o ./hello 成功运行