使用ASM THUMB将值写入GBA上的内存

时间:2016-04-17 13:10:33

标签: assembly arm gba

嘿,我正在开展一个简单的大学项目并为GameBoy Advanced制作游戏。

我一直在玩asm,打算通过ASM和THUMB模式创建我的调色板。

我尝试使用ldrstr将内存地址0x0500000(调色板内存)加载到寄存器中并存储0x253F(红色)等值并将其存储到调色板地址中。怎么可以这样做?我也试过使用MOV,但也没有成功。

下面的代码编译,但它似乎无法正常工作

.THUMB              @ turn on thumb
.ALIGN  2           @ align code correctly for GBA
.GLOBL  test        @ name of function goes here

.THUMB_FUNC         @ we are about to declare a thumb function
test:               @ function start

push { r4-r7, lr }  @ push r4-r7 and link register onto stack. Your function might use these
                @ registers, so we need to preserve the values just in case!
                @ we don't need to worry about r0-r3 as it is assumed they will be regularly messed up anyway


@ the magic happens here!
@ r0-r3 will automatically contain the parameters sent when calling the function.


ldr r5, =#0x5000000
ldr r4, =#0x03DF
str r5, [r4]

pop { r4-r7 }       @ pop first 4 values from stack back into r4-r7, and also
pop { r3 }          @ pop the next value from stack (stored value for lr) into some unused register, e.g. r3 -
                @ we cannot overwrite lr so we have to do it via a normal register
bx r3               @ "branch and exchange" (return) back to C, using the     previous value for lr stored in r3
 @ ==================================

我真的很感激任何帮助

0 个答案:

没有答案