How to use assembly in the source code ?

Post Reply
karmaGfa
Posts: 2
Joined: Fri Sep 03, 2010 2:28 pm

How to use assembly in the source code ?

Post by karmaGfa » Sat Sep 04, 2010 10:34 am

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 ?

User avatar
fincs
( ͡° ͜ʖ ͡°)
Posts: 103
Joined: Mon Jul 12, 2010 9:45 pm
Location: Seville, Spain
Contact:

Re: How to use assembly in the source code ?

Post by fincs » Sat Sep 04, 2010 6:44 pm

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)
Donate to devkitPro - help us stay alive!

karmaGfa
Posts: 2
Joined: Fri Sep 03, 2010 2:28 pm

Re: How to use assembly in the source code ?

Post by karmaGfa » Sun Sep 05, 2010 8:00 am

Thank you a lot, that's all I needed.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests