How to link two nasm source files

I have a file that defines very simple I / O functions and I want to create another file that uses this file.

Is there a way to link these two files?

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 my question) call os_return ;and this too.. 

Please note that these are not actual files ... They are just used to explain my problem :)

Thanks!

+6
source share
1 answer

Of course, you just need to use the linker. Collect 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. Sort of:

 gcc -o myProgramName prints.o usingPrintTest.o 

Using gcc , because the linker driver can solve some kind of funny business by linking the OS libraries needed to run your program. You may need to make some declarations in usingprintTest.asm so that it knows that print_Achar and os_return will be defined elsewhere - in nasm , you will use the extern assembler directive:

 extern print_Achar extern os_return 
+4
source

Source: https://habr.com/ru/post/901832/


All Articles