GP32 Aapcs


Has anyone experience in using AAPCS to call assembler functions from C/C++?

Calling routines with four or fewer parametrs seems simple, I did find mention of calling from C++ then a1 = this, so you would maybe need to wrap calls to be able to call them from both?

My problem is calling assembler routines from C/C++ with 5 parameters. I thought it may be as simple as pulling the last param of the stack! But it seemes to be more involved than this?

I have looked through the ARM documents but am not able to find an example or good explanation of using AAPCS, can anyone help please.
 
Well actually, it's not harder than this. Besides, I never tried it with c++, so maybe it won't be any help for you, but anyway:

Let's say you want to send 6 parameters:

Code:
sub	sp,sp,#8            @protect the memory where the params are
stmfd	r13!,{r6-r12}     @save used registers
ldr	r6,[r13,#36]       @then load the 5th and 6th params using ldrs
ldr	r7,[r13,#40]       @2 params + 7 saved registers (4 bytes each)
                       @=> 9 x 4 = 36 bytes from sp (r13), and then 40

And don't forget to put back the old values for the registers using:

Code:
ldmfd	r13!,{r6-r12}
add	sp,sp,#8
bx	lr
 
Thanks for the example, thats just what i needed. Reading through stacks of ARM ref material had started to fry my mind.

is there a reason you use the following to return:

ldmfd r13!,{r6-r12}
add sp,sp,#8
bx lr

rather than :

ldmfd r13!,{r6,r2,lr}
 
Well, I found that example in the Elite port source actually, and I used it as it was. But I think the only difference is that with this method you can return to any mode (thumb or arm).
 
Back
Top