gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > ASM command question?

#1862 - regularkid - Fri Jan 24, 2003 6:40 pm

Hi, I found this code on GBADev.org about calling an ASM function from C code:

Code:

@ Draw pixel in GBA graphics modes 3/5 in ARM asm (fast)
@ Entry: px = pixel X coordinate
@        py = pixel Y coordinate
@     color = pixel color
@   scrnadr = base screen address
@ (void) DrawPixel32 (u32 x, u32 y, u32 color, u32 scrnadr);

        .ARM
        .ALIGN
        .GLOBL  DrawPixel32

DrawPixel32:
        stmfd   sp!,{r4-r5}

        mov     r4,#480
        mul     r5,r4,r1
        add     r5,r5,r0,lsl #1
        add     r4,r5,r3
        strh    r2,[r4]

        ldmfd   sp!,{r4-r5}
        bx      lr


My quesions:

1. Where are the parameters stored? I think it said lowest registers, but I just want to make sure.
2. What does this do:
stmfd sp!,{r4-r5}
3. What does this do:
ldmfd sp!,{r4-r5}

thanks!
_________________
- RegularKid

#1864 - Touchstone - Fri Jan 24, 2003 7:23 pm

1. Parameters are stored in r0-r3 (I think it's no further than r3), the rest is stored on the stack.

2. Store multiple registers, as opposed to regular store register (str). The exclamation-mark indicate what to do with the destination register. What that exact line does is push r4 and r5 to the stack.

3. Load multiple registers. Pop r4 and r5 from the stack.
_________________
You can't beat our meat