Memory Copy in ASM [PoptartHunter]

In this tutorial, I'll be teaching you how to copy a value at an address, and write that value to another address, similar to the 80 and 8A codetypes. First of all, you'll need to download the ASM<->WiiRd Converter tool to convert your asm to a gecko code.


Now you will want to load the address of the value to be copied into a register. You will use lis and ori instructions, which stand for "load immediately shifted left by 16 bits" and "or immediate".


Say the address you want to copy the value from is 80308234


To easily load this into a register, you want to do this:


lis r11,0x8030 # loads first half of address, shifted to the left 16 bits (4 digits)

ori r11,r11,0x8234 # loads second half of address, this time NOT shifted at all


What this does is..


lis r11, 8030 will load the value 8030 into register 11, but it will shift it left by 16 bits. So r11 will look like 8030XXXX


now, the ori instruction loads the second half of the address, this time NOT by 16 bits.


So those two instructions together will make r11 hold the address 80308234 when used in conjunction.


Next, you'll want to load your other address into another register. Let's say the address we wanted to write the copied value to is 80802360. You'll do the same thing as we did above.


lis r12,0x8080

ori r12,r12,0x2360


So far our assembly looks like this:


lis r11,0x8030

ori r11,r11,0x8234

lis r12,0x8080

ori r12,r12,0x2360


After loading our addresses into registers, we want to get our value from the first address in r11 to write to the second address in r12.


To get the value at 80308234, we're going to be using the instruction lwz, which means "load word zero". A "word" is 32 bits (8 digits).


the lwz instruction is going to look like so:


lwz r13,0(r11)


What that gibberish means is, it will take the value at the address in r11 (80308234), and it will store that value into r13.


So now that you have loaded both of your addresses into registers, and have loaded the value that you want to be copied to another address into a register, our assembly will look like this:


lis r11,0x8030

ori r11,r11,0x8234

lis r12,0x8080

ori r12,r12,0x2360

lwz r13,0(r11)

The next and final step in our assembly will be the actual "copying" of the stored value and writing of it to our other address in r12, which is 80802360. For this we will be using the "stw" instruction, which stands for "store word". In order to make the assembly "copy" the value stored in r13 and write it to the address in r12, we will need to do this:


stw r13,0(r12)


This instruction will take the value in r13, and write it to the address in r12, the last step in copying a value from one address to another. Here's our finished assembly commented:


lis r11,0x8030 # load 8030 into r11 shifted left by 16 bits

ori r11,r11,0x8234 # load second half of address, 8234

lis r12,0x8080 # load 8080 into r11 shifted left by 16 bits

ori r12,r12,0x2360 # load second half of address, 2360

lwz r13,0(r11) # load the value at the address in r11 (80308234) and put that value into r13

stw r13,0(r12) # Write the loaded value in r13 to the address in r12 (80802360)

blr

blr # C0 codes always have to end in a blr


and he's our compiled code:


C0000000 00000005

3D608030 616B8234

3D808080 618C2360

81AB0000 91AC0000

4E800020 4E800020

E0000000 80008000