.text
.align 2
.thumb
.thumb_func
This is required for all ASM hacks.
.global lesson1
you put the name of the file after .global
main:
The main event
push {r0-r1, lr}
push takes the data stored and moves it away so you can use free space. In this case we are freeing r0 and r1. You MUST put lr after pushing.
ldr r0, .PLAYER_DATA
Loads PLAYER_DATA into r0. ldr=load r
If you notice, at the bottom we define what exactly player_data is. It is the data stored at address 0x0300500C which IS the player's data.
ldr r0, [r0]
we are loading again but it's loading Itself? Yes, because 0x0300500C is a pointer, and if we load the pointer we load the data at the actual offset. so now r0 loads the actual data, instead of a pointer.
ldr r1, .VAR
We haven't used r1 yet, but now we load VAR into r1. r1 still has free space up until now. VAR is also a pointer, but it is a pointer to Variable 0x800D. So now, r1 IS Variable 0x800D.
ldrh r0, [r0, #0xC]
Now we use ldrh. It loads still, but a Half-word instead. If we used ldrb, it would load a byte, but that is too small. r0 still has our player data, but let's look for our secret ID #. our secret ID is 12 bytes away from the player data, and 12 in hex is 0xC. So we load the Half-word stored 12 bytes away from the player data, which is EXACTLY where our secret ID is stored. r0 now has our Player's secret ID.
strh r0, [r1]
str=store. strh=store half-word. It stores the data in r0 which is our secret ID into r1 which is Variable 0x8004. Now Variable 0x8004 has our secret ID!
pop {r0-r1, pc}
It is the opposite of push. push cleans r0 and r1, pop returns the previous data before we used the r's. Like push, you must always put pc when popping.