Thread: [Tutorial] GBA ASM Programming
View Single Post
Old January 6th, 2011 (7:37 PM).
NintendoBoyDX NintendoBoyDX is offline
Join Date: Jul 2010
Gender: Male
Posts: 94
Thanks Xenesis, colcolstyles. There was just one more thing that wasn't clear to me:
.word 0x020270B6 + (0x800D * 2)
If the 0x8000-0x8013 variables are the only static one, how would there be an address of the "first" variable(I assume 0x0000), wouldn't it be DMA along with the rest?

BTW, looking at an example code from a tutorial JPAN posted a while ago, he subtracts 0x8000 from his variable values, multiplies them by 4, then finally adds that to the 0x8000 variable's address. I don't understand why it would be necessary to do that(or how that works quite frankly), even though with the code in this tutorial you can simply store the value to loaded variable.
Here was the code:
                          .align 2
  Var_adder:      push {r0-r2, lr}
                          Ldr r0, first_var_addr @this will load the address of that lable
                          Ldrh r0, [r0, #0x0]      @and this will load its content.
                          Ldr r1, second_var_addr
                          Ldrh r1, [r1, #0x0]      @both variable numbers are loaded   
                          Lsl r2, r2, #0x10          @cleans the bottom half of register r2
                          Add r2, r2,#0x8          @places 0x8 in r2
                          Lsl r2, r2, #0xc            @and this turns 0x8 in 0x8000, and cleans the rest                                                               @of r2             
                          Sub r1, r1, r2               @leaves only the last value in
                          Sub r0, r0, r2               @each variable.
                          Lsl r1, r1, #0x2            @after multiplied by 4, It becomes the 
                                                              @offset of that address
                          Ldr r2, var_8000_addr
                          Lsl r0, r0, #0x2            @same here.
                          Add r0, r2, r0              @by adding the variable address to the offest
                          Add r1, r2, r1              @you get the correct variable address
                          Ldrh r2, [r0, #0x0]      @now we load the content of the variables we
                          Ldrh r1, [r1, #0x0]      @want to add
                          Add r2, r1, r2              @and add them
                          Strh r2, [r0, #0x0]       @the result, that is in r2, is placed in the first                                                                        @variable, the one in 0x8013
                          Pop {r0-r2, pc}           @and we’re done
  first_var_addr: .word 0x020370dc
  second_var_addr:.word 0x020370de
  var_8000_addr:.word 0x020370b8
Reply With Quote