-
Notifications
You must be signed in to change notification settings - Fork 0
Debugger Instructions for Nintendo Wii
The Nintendo Wii runs with 32-bit PowerPC assembly and this guide explains how to interpret instructions as they appear in a Nintendo Wii debugger, such as the one included in the Dolphin emulator. Note that the explanations do not describe each instruction in full technical detail, nor is it meant to be a perfectly accurate representation of everything happening internally. Instead, the goal is to provide simple, approachable explanations of what each instruction does so developers can better understand how to read them.
The debugger in the Dolphin emulator can be accessed by using the following path: Options > Configuration > Interface > Enable Debugging UI
Instruction:
addis RT, RA, SI
The instruction loads the value stored in SI and multiplies it with 0x10000. The results is then added to the value in RA with the sum being stored in RT.
Example:
r3 = 0x81532C40
addis r4, r3, 2
The value of 2 (SI) is multiplied with 0x10000, resulting in a value of 0x20000. This result then gets added to 0x81532C40 (r3) resulting in a value of 0x81552C40, which gets stored into r4.
Info:
This instruction seems to be often followed with another instruction which uses RT to access an address using a small or negative offset. This is done to avoid large offsets for pointers. If such a pointer is accessed, it is recommended to just calculate the full offset together right away by doing SI * 0x10000 + offset and using the result as offset for the pointer.
Instruction:
lha RT, D (RA)
The instruction loads the 16-bit value found at the address target calculated with RA + D and stores it into the lower 16-bit of RT. Then it reads Bit15 of RT and copies the value of the bit into all bits in the upper 16-bit section.
Example 1:
r31 = 0x80D5CF28 Mem 0x80D5D0AA = 0x0724
lha r3, 0x182 (r31)
The values 0x80D5CF28 (r31) and 0x182 (D) get added resulting into an address reference of 0x80D5D0AA. The 16-bit value of 0x80D5D0AA is currently 0x0724, so r3 becomes 0x00000724. Then Bit15 of 0x0724 is read, which is 0, and gets copied into Bit16 to Bit31 of r3. So the final value stored into r3 is 0x00000724.
Example 2:
r31 = 0x80D5CF28 Mem 0x80D5D0AA = 0x8724
lha r3, 0x182 (r31)
The values 0x80D5CF28 (r31) and 0x182 (D) get added resulting into an address reference of 0x80D5D0AA. The 16-bit value of 0x80D5D0AA is currently 0x8724, so r3 becomes 0x00008724. Then Bit15 of 0x8724 is read, which is 1, and gets copied into Bit16 to Bit31 of r3. So the final value stored into r3 is 0xFFFF8724.
Instruction:
lis RX, SI
The instruction loads the value in SI and stores it into RX.
Example:
lwz r0, 1
The value of 1 is stored into r0, resulting into r0 being 0x00000001.
Instruction:
lis RX, SI
The instruction loads the value in SI and multiplies it with 0x10000. The result value is then stored into RX.
Example:
lwz r3, 0x80D6
The value of 0x80D6 is multiplied by 0x10000 resulting in 0x80D60000. The result value is then stored into r3.
Info:
Since this instruction writes a fix value into a register, it is often used to set the leading 16-bit of a register used for a pointer.
Instruction:
lwz RT, D (RA)
The instruction loads the value found at the address target calculated with RA + D and stores it into RT. The instruction can be interpreted similar to an AddAddress call where RA is the value of a pointer address and D being the offset.
Example:
r24 = 0x8155ef68
lwz r0, 0x0040 (r24)
An address target is calculated by adding 0x8155ef68 (r24) and an offset of 0x0040 (D), resulting into 0x8155efa8. Then the value at 32-bit 0x8155efa8 is stored into r0.
Instruction:
stb RS, D (RA)
The instruction writes the value stored in RS to the 8-bit of the address target calculated with RA + D. The instruction can be interpreted similar to an AddAddress call where RA is the value of a pointer address and D being the offset.
Example:
r3 = 0x81543340
stb r4, 0x14 (r3)
The instruction create a memory reference by adding 0x81543340 (r3) and an offset of 0x14 (D), resulting into 0x81543354. Then the value stored in r4 is written into the 8-bit of 0x81543354.
Instruction:
stw RS, D (RA)
The instruction writes the value stored in RS to the 32-bit of the address target calculated with RA + D. The instruction can be interpreted similar to an AddAddress call where RA is the value of a pointer address and D being the offset.
Example:
r3 = 0x81543340
stw r4, 0x14 (r3)
The instruction creates a memory reference by adding 0x81543340 (r3) and an offset of 0x14 (D), resulting into 0x81543354. Then the value stored in r4 is written into the 32-bit of 0x81543354.
Info:
The instruction name "word" would imply that it's just a 16-bit value write since 32-bit would normally be called double word. However, this instruction extends the 16-bit to 32-bit.