Link wrote:
D9000040 00000000 //load the value at offset 40 (if I got that correctly, this value is now in r3)
I might have given false informations somewhere I guess. That's not in r3 at all.
Here is where it is stored :
[r13] = 'Dx repeat value'
[r13+0x4]= 'Dx next code to be executed'
[r13+0x8] = 'Dx code status'
[r13+0xC]='Dx data'
Also, the good syntax for the D9 code type is :
D9000000 00000040
And you make a ldr r0,=0x20A8A40, but after should follow a ldr r0,[r0] (else r0=0x020A8A40, and not [0x020A8A40]). You should also check that the pointer is not null at the very start of your code (62084038 00000000 - and then change the second D3000000 00000000 with a D2000000 00000000.).
Then I'm not quite sure if 0x023FFFF8 is really an unused place. Never looked into it (I prefer to use 0x02000000 - and I believe you could even use the ARM9 entry point in your case).
Finally, your way of comparing the 2 values is strange. A=B is not the same than A&(!B)=0
(2 and !6 =0, but 2!=6...). You should just xor them (unless you did that on purpose?).
Anyway, I also advise you do everything using asm (and not mix up ARDS and ASM) for your case, it'll be more efficient, but that's really up to you (it's kinda code size versus code efficiency - some people prefer small codes (by using the C code type for exemple), even if they do a crappy job).
ie. something like that (might be buggy I didn't try to compile it, it's just to give you an idea) :
Code:
---asm---
ldr r1,data // r1=0x02084038
ldr r0,[r1] // r0= 32bits value at 0x02084038
cmp r0,#0x0 // checks if the pointer exists
beq end // exits if the pointer is null (and then as r0=0, 0x02084038 (r1) will be written to 0x023FFFF8).
ldr r0,[r0,#0x40] // loads the 32bits value at 0x02084038+0x40
ldr r1,data+#0x04 // r1= 0x020A8A40
ldr r1,[r1] // r1= 32bits value at 0x020A8A40
end:
eor r1,r0 // if r1=r0 then r1=0, else r1!=0 - shouldn't we check if r1!=0 too ?
mov r0,#0x02400000
str r1,[r0,#-0x08] // stores r1 at 0x023FFFF8
bx r14 // jumps back to the AR
data:
.word 0x02084038
.word 0x020A8A40
---asm end---
523FFFF8 00000000 //now is the value which was just written really 00000000
____ //instructions here
D2000000 00000000 //end