Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include assembly file in another assembly file

I have two files, main.s and test.s where test.s looks like this:

test:
   add a1,a2,a2

...and main.s looks like this:

main:
   call test

(very senseless examples). How can I include test in main? I am using gcc like this:

gcc -o main main.c

But I have no idea how I can use test in there...any help?

like image 723
今天春天 Avatar asked Sep 11 '25 18:09

今天春天


2 Answers

You can include the file just as you would with anything else in GCC:

 #include"test.S"

Were you using NASM you would use:

 %include "test.s"
like image 67
David Hoelzer Avatar answered Sep 14 '25 08:09

David Hoelzer


Addition to @david-hoelzer 's answer:

If you, like me, use gcc -c, include instruction should be like that:

.include "test.s"

GCC:

gcc -c main.s test.s
ld -o main main.o test.o
./main
like image 45
listvennica Avatar answered Sep 14 '25 07:09

listvennica