Tutorial on the 'Pointer Trick' (ASM)
Tutorial on the Pointer Trick

NOTICE: For beginner-level ASM Coders.

Sometimes a breakpoint can fail, or only occur during certain situations. Thus, a coder will then try to find another viable breakpoint for the dynamic memory value(s) they are wanting to manipulate. However, sometimes no breakpoints will be viable, or finding the correct value to break is too difficult to find.

Explanation Of When To Use Pointer Trick

For example: In this code HERE, if one were to breakpoint the value in dynamic memory of the Trick Boost amount for a single conventional ASM, well it wouldn't work. If the value for the trick boost is zero, it wont break with a read nor a write BP. There are multiple different functions (addresses) that are responsible for increasing the value, decreasing the value, etc.

Instead of trying to make a code that contains multiple ASMs to cover every function listed, we do what's called the Pointer Trick instead. A pointer is simply a value at a non-dynamic memory address (any plain standard code address) that contains (points to) the current dynamic memory address of where your desired value is located

What you do is find a nearby value that is not too far away from the value you would normally set a BP on. You need to find a value that gets read or written to every frame. Meaning it will break any time that you need it to break. For the Trick Boost Meter code, we need a value that will break at any point during the live race. 

This will take some trail and error obviously. There was a value I found that breaks at any point during the race (write BP). It is a halfword value that is 0x004C before the Trick Boost Halfword value.

Explanation Of Source Instructions

Let's view the source of the Trick Boost Meter. There's two ASMs. I will explain each function. Let's start with the second ASM first. the ASM responsible for making the pointer.

sth r27, 0x00C8 (r3) #Default ASM

So the first ASM function is the default ASM that is called upon. It's what I was lead to when I set a write BP on the value that was 0x004C before the Trick Boost value. 

addi r12, r3, 0x114

We see that the default ASM is using the address value of r3 as a reference to store its half word to in dynamic memory, we will also use r3 to calculate our pointer. Since our Trick Boost value is 0x004C further in memory, just add 0xC8 plus 0x4C. The result is 0x114. All we have to do is now add the contents of r3 and 0x114 together... r12 is always safe to use ofc.

Okay so r12 now contains the pointer (dynamic memory address of where the Trick Boost halfword value is). We need to store that value somewhere, and have our other ASM read it for the millisecond display of the race timer. We will use a random spot in the crash handler like most codes would use as a place to load/store values.

lis r11, 0x8000
stw r12, 0x1650 (r11)

Alright, so our r12 value is stored to 0x80001650. Moving onto the code's first ASM, the ASM that will display the Trick Boost value.

This ASM uses r5 as the display value for the millisecond section of the timer. So we need to load our pointer value into a register. Then simply load the halfword value (Trick Boost) from the memory address of the pointer into r5. First, load the pointer value.

lis r12, 0x8000
lwz r12, 0x1650 (r12)

r12 now contains our pointer. So now we just run another load function. Obviously, we need to use a lhz to load the halfword value since that is the byte-length of how the Trick Boost value is shown in memory.

lhz r5, 0 (r12)

We simply load the Trick Boost halfword right into Register 5. Normally the default function of this codes' address for this ASM is lwz r5, 0x0024 (sp). But we don't need the default ASM, since we already have our value in r5 that we need to display on the milliseconds section of the timer. Thus, we are completely finished.


Alright, so now you know not to give up hope entirely if your breakpoints are not working. Try the pointer trick, it may get your code to work. Thanks for reading.

Forum Jump:

Users browsing this thread: 1 Guest(s)