GBA ARM Build Help

I tried to modify this ARM build program (see bottom of the page) to use routines. It should display a red screen on the GBA (and compile an example program that it actually does, so this is not a problem using the toolchain), but when I run it, the screen turns black instead. I am using devkitARM 30

.arm .text .global main main: mov r0, #0x4000000 mov r1, #0x400 add r1, r1, #3 str r1, [r0] mov r0, #0x6000000 stmdb sp!, {r0, r2, lr} @push registers before calling mov r0, #0xff mov r1, #0 mov r2, #0 bl set_rgb mov r1, r0 ldmdb sp!, {r0, r2, lr} @restore registers mov r2, #0x9600 loop1: strh r1, [r0], #2 subs r2, r2, #1 bne loop1 infin: b infin set_rgb: @r0: R; r1: G; r2: B; r0: RGB @truncate everything but the least significant five bits and r0, r0, #0x1f and r1, r1, #0x1f and r2, r2, #0x1f @form the color orr r0, r0, r1, lsl #5 orr r0, r0, r2, lsl #10 mov pc, lr @return 

The question is what's wrong with this program?

+4
source share
2 answers

I decided it myself.

The problem was how I used the stack. Instead of stmdb and ldmdb I needed to use stmfd and ldmfd .

+3
source

stmdb means decrement to and then use this address to start writing to the stack, this is correct. ldmia means incrementing after that, starting with the current stack pointer, to read the values ​​back into their registers, and then increment the stack pointer. The fd nomenclature never made sense to me. Like a jump, if it is equal and jumps, if zero is the same instruction for all processors, and some asms offer both, there are only two options: ldm and stm db, ia, fd, all cards in these two flavors. It’s easier for me to remember the increment after (ldmia) and the decrement before (ldmdb). Or, if for some reason you turn the load / storage direction bit, you still choose the right step before or after, depending on what you are trying to do.

In C, it's like * (ptr ++) vs * (++ ptr)

0
source

Source: https://habr.com/ru/post/1308008/


All Articles