【问题标题】:How to link two nasm source files如何链接两个nasm源文件
【发布时间】:2012-01-01 11:44:11
【问题描述】:

我有一个定义非常基本的 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..

请注意,这些不是实际文件...它们只是用来解释我的问题 :)

谢谢!

【问题讨论】:

    标签: compiler-construction assembly linker nasm extern


    【解决方案1】:

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

    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
    

    【讨论】:

    • 非常感谢。当我们进行一些激烈的谷歌搜索时,我们在你得到它之前想出了答案:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2011-10-11
    • 2016-07-14
    • 2012-05-09
    • 2017-05-26
    • 2017-08-21
    相关资源
    最近更新 更多