Page 1 of 1

How to use assembly in the source code ?

Posted: Sat Sep 04, 2010 10:34 am
by karmaGfa
Hello,

I would like to write a few functions using assembly in my C program, for GBA.

I don't find the documentation explaining how to do that. I tried to read the source code of the libgba, but it is still unclear to me how parameters are passed from the C function declaration to its assembly implementation.

Could someone explain me or point me to a documentation, please ?

Re: How to use assembly in the source code ?

Posted: Sat Sep 04, 2010 6:44 pm
by fincs
Use this code as a template (save it with .s extension):

Code: Select all

.arch armv4t @ target the ARMv4T architecture (on which the GBA's ARM7TDMI processor is based)

.section .iwram, "ax", %progbits @ use fast 32k RAM for ARM code
.align 2

.global myFunc
myFunc:
    bx lr @ return
The ARM calling convention is simple: all parameters are made 32-bit (sign-extending if necessary), the first four parameters go in the r0-r3 registers, all others are pushed on the stack.

Links:
Tonc: Whirlwind Tour of ARM Assembly
[PDF] ARM Architecture Procedure Call Standard (AAPCS)

Re: How to use assembly in the source code ?

Posted: Sun Sep 05, 2010 8:00 am
by karmaGfa
Thank you a lot, that's all I needed.