p + n is not + n
Pointers count in elements. Add 5 to an int* and you don't move 5 bytes, you move 5 ints. The compiler handles that scaling. It multiplies your offset by sizeof(*p) before anything reaches a register, and for a constant offset the math finishes at compile time, so the byte count is already baked into the addi.
Five elements into an int array:
int* advance5(int* p) {
return p + 5;
}
addi r3, r3, 20 # advance p by 5 * sizeof(int) = 20 bytes
blr
An int is 4 bytes. Five times 4 is 20, and 20 is what the addi carries. Going backward from the disassembly you flip the operation. Take the immediate, divide by the element size, and the quotient is how many elements the pointer moved.
Here's a gotcha. p + n and &p[n] produce byte-identical assembly, since both land on the nth element's address. The output keeps the secret of which one the author typed, so just write whichever is easier to read.
So advance3. What's the immediate on its addi, and how many elements does that work out to?
Your task
Write advance3 so it compiles to the addi above.