如何链接两个 nasm 源文件

发布于 2024-12-17 04:00:19 字数 557 浏览 0 评论 0原文

我有一个定义非常基本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痕至 2024-12-24 04:00:19

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

nasm -o prints.o prints.asm
nasm -o usingPrintTest.o usingPrintTest.asm

然后您可以将输出对象传递给链接器。例如:

gcc -o myProgramName prints.o usingPrintTest.o

使用 gcc 作为链接器驱动程序可以通过链接程序运行所需的操作系统库来解决一些有趣的问题。您可能需要在 usingprintTest.asm 中进行一些声明,以让它知道 print_Acharos_return 将在其他地方定义 - 在 中>nasm,您将使用 extern 汇编器指令:

extern print_Achar
extern os_return

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文