Everything depends on how you want to write your asm:
Either inline, or in .s source files. Personally, I prefer having my .s source file (you can find examples on many sources, as for example Newkind (elite port), which embeds some useful code for line and dot drawing. You can assemble a .s file using as:
as -o line.o line.s
Then you get your .o file, that you can add to your makefile like this:
OBJS =\
gpmain.o\
gpstart.o\
line.o <== add this
Then you can use the funcs inside your line.o from the c, maybe you'll have to define them in a .h file first:
extern void .......
To send args to an asm func, here it is:
The first 4 datas are mapped into r0 - r3, so if your function has less that or 4 args, no problem.
After that, the data can be recovered using this method:
sub sp,sp,#8 We protect the stack so that our other args don't get overwritten
stmfd r13!,{r4-r5} We save the registers we use
ldr r4,[r13,#16] 2 values saved, plus 2 registers = 4 values, 4 bytes each
ldr r5,[r13,#20] So to read the last args, use offsets of 16 and 20 to get the right value (in this example)
I won't be very helpful for returning values, as I never used it before...
To return from thez func, use this:
ldmfd r13!,{r4-r5} Recover the saved registers
add sp,sp,#8 Leave the stack as it was
bx lr Return from the function
Here's a full example:
s. file:
@ ******** ASMSaveBitmap(unsigned char *src4, unsigned char *dst, int nbx, int nby, int height2) ********
.ALIGN
.GLOBAL ASMSaveBitmap
.TYPE ASMSaveBitmap, function
.CODE 32
@r0 = src4
@r1 = dst + 1
@r2 = nbx
@r3 = nby
@r7 = height2
@r8 = tmp
@r9 = tmpnby
@r10 = dst4
ASMSaveBitmap:
sub sp,sp,#4
stmfd r13!,{r7-r10}
LDR r7,[r13,#20]
_bx5:
MLA r10,r2,r7,r1
MOV r9,r3
_by5:
LDRB r8,[r0,+r9]
SUBS r9,r9,#1
STRB r8,[r10,+r9]
BPL _by5
SUB r0,r0,#240
SUBS r2,r2,#1
BPL _bx5
ldmfd r13!,{r7-r10}
add sp,sp,#4
bx lr
.h file:
extern void ASMSaveBitmap(unsigned char *src4, unsigned char *dst, int nbx, int nby, int height2);
.c file:
static inline void SaveBitmap(int numsurface, int dx, int dy, int width, int height, unsigned char *dest) { //Sur l'écran
int xmin = 0;
int ymin = 0;
int xmax = width - 1;
int ymax = height - 1;
int height2 = ( (height + 3) >> 2) * 4;
int decaly = screen_height - height - dy;
if(dx < 0) { //Fast clipping, décale juste le tracé
xmin = -dx;
} else if( (dx + width) > screen_width) xmax = screen_width - dx - 1;
if(dy < 0) {
ymax = height + dy - 1;
} else if( (dy + height) > screen_height) ymin = dy + height - screen_height;
if(xmin > xmax) return;
if(ymin > ymax) return;
unsigned char *src4 = gpDraw[numsurface].ptbuffer + (dx + xmax) * screen_height + decaly + ymin;
dest += (xmin * height2 + ymin + 1);
ASMSaveBitmap(src4, dest, xmax - xmin, ymax - ymin, height2);
}
Hope that helped.