Compiler construction 如何链接两个nasm源文件

Compiler construction 如何链接两个nasm源文件,compiler-construction,assembly,linker,nasm,extern,Compiler Construction,Assembly,Linker,Nasm,Extern,我有一个定义非常基本IO函数的文件,我想创建另一个使用该文件的文件 有没有办法把这两个文件连接起来 prints.asm: os_return: ;some code to return to os print_AnInt: ;some code to output an int, including negatives - gets param from stack print_AChar: ;some code to output a char - gets para

我有一个定义非常基本IO函数的文件,我想创建另一个使用该文件的文件

有没有办法把这两个文件连接起来

prints.asm:

os_return:
    ;some code to return to os
print_AnInt:
    ;some code to output an int, including negatives - gets param from stack
print_AChar:
    ;some code to output a char - gets param from stack
使用PrintTest.asm:

main:
   push qword 'a'
   call print_AChar ;gets this from prints.asm somehow (that's my question)
   call os_return   ;and this too..
请注意,这些不是实际的文件。。。它们只是用来解释我的问题:)


谢谢

当然-您只需要使用链接器。组装每个文件:

nasm -o prints.o prints.asm
nasm -o usingPrintTest.o usingPrintTest.asm
然后可以将输出对象传递给链接器。比如:

gcc -o myProgramName prints.o usingPrintTest.o
使用
gcc
作为链接器驱动程序可以解决一些有趣的问题,比如链接程序运行所需的操作系统库。您可能需要使用printTest.asm在
中进行一些声明,让它知道
print\u Achar
os\u return
将在其他地方定义-在
nasm
中,您将使用
extern
汇编指令:

extern print_Achar
extern os_return

谢谢你,伙计。当我们在谷歌上搜索的时候,我们在你得到答案前几秒钟就找到了答案:P