puppydrum64
puppydrum64

Reputation: 1688

Using gcc to combine assembly code with C

I was trying to combine a simple assembly program to copy data from one place to another (essentially the ARM equivalent of Z80's LDIR command). The problem I ran into was how to tell GCC to combine it with my C code. I had it working before but I forgot what I did since I didn't maintain the old batch file (mistake number 1). Then I tried to re-create it from memory and ended up deleting my hello.c file! (mistake number 2). Luckily it only took me about 15 minutes to rewrite it since most of it was include statements from other files.

The source code for the asm is here, and this is my batch file:

set path=C:\devkitadv\devkitadv-r5-beta-3\bin;%path%

as -o memcpy.o memcpy.s
gcc -S -o hello.asm hello.c
gcc -o hello.elf hello.c -lm
objcopy -O binary hello.elf hello.gba
pause

I'm not sure how to link memcpy.o to hello.c or hello.elf (whichever needs it). I read here that it's best to use the C compiler for linking rather than manually calling ld but I don't really understand how to do that. Batch isn't my strong suit, and unfortunately it seems like I have to know how to use it to get anything to work.

Upvotes: 2

Views: 346

Answers (0)

Related Questions