如何链接两个 nasm 源文件
我有一个定义非常基本的 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
usingPrintTest.asm:
main:
push qword 'a'
call print_AChar ;gets this from prints.asm somehow (that's my question)
call os_return ;and this too..
注意这些不是实际的文件...它们只是用来解释我的问题:)
谢谢!
I've got a file that defines very basic IO functions and I want to create another file that uses this file.
Is there a way to link these two files up?
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
usingPrintTest.asm:
main:
push qword 'a'
call print_AChar ;gets this from prints.asm somehow (that's my question)
call os_return ;and this too..
Note these aren't the actual files... They're just used to explain my problem :)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然 - 你只需要使用链接器。组装每个文件:
然后您可以将输出对象传递给链接器。例如:
使用 gcc 作为链接器驱动程序可以通过链接程序运行所需的操作系统库来解决一些有趣的问题。您可能需要在
usingprintTest.asm
中进行一些声明,以让它知道print_Achar
和os_return
将在其他地方定义 - 在中>nasm
,您将使用extern
汇编器指令:Sure - you just need to use the linker. Assemble each of your files:
You can then pass the output objects to your linker. Something like:
Using
gcc
as the linker driver can solve some funny business with linking the OS libraries you need for your program to run. You might need to make some declarations inusingprintTest.asm
to let it know thatprint_Achar
andos_return
are going to be defined elsewhere - innasm
, you'll use theextern
assembler directive: