我有一个定义非常基本的 IO 函数的文件,我想创建另一个使用该文件的文件。
有没有办法将这两个文件链接起来?
打印.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
因为链接器驱动程序可以通过链接程序运行所需的操作系统库来解决一些有趣的问题。您可能需要在 usingprintTest.asm
中进行一些声明让它知道 print_Achar
和 os_return
将在别处定义 - 在 nasm
中,您将使用 extern
汇编指令:extern print_Achar
extern os_return
关于compiler-construction - 如何链接两个nasm源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8187028/