0

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

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

我尝试使用ldr并将str内存地址(调色板内存)加载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
 @ ==================================

我真的很感激任何帮助

4

0 回答 0