如何连接两个NASM源文件 [英] How to link two nasm source files
问题描述
我有一个定义非常基本的IO功能的文件,我想创建一个使用此文件中的另一个文件。
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:
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:
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 :)
谢谢!
推荐答案
当然 - 你只需要使用连接器。组装每个文件:
Sure - you just need to use the linker. Assemble each of your files:
nasm -o prints.o prints.asm
nasm -o usingPrintTest.o usingPrintTest.asm
您可以再通过输出对象到链接器。是这样的:
You can then pass the output objects to your linker. Something like:
gcc -o myProgramName prints.o usingPrintTest.o
使用 GCC
作为连接器驱动程序可以解决一些有趣的业务关联,您需要为您的程序运行OS库。您可能需要做一些报关单 usingprintTest.asm
来让它知道 print_Achar
和 os_return
将要在其他地方定义 - 在 NASM
,你会使用的extern
汇编指令:
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 in usingprintTest.asm
to let it know that print_Achar
and os_return
are going to be defined elsewhere - in nasm
, you'll use the extern
assembler directive:
extern print_Achar
extern os_return
这篇关于如何连接两个NASM源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!