The out-parameter
Last chapter every pointer was something you read through. This chapter turns the arrow around and then spends serious time on the addresses themselves. First, the write: sw rt, offset(base) — store word — copies a register into memory at base + offset. Here's put_inc, which delivers x + 1 through a pointer instead of returning it:
void put_inc(s32 *out, s32 x) {
*out = x + 1;
}
addiu t6, a1, 1 # x + 1, computed into scratch
sw t6, 0(a0) # *out = the result
jr ra
nop
Two things worth pinning down:
- The value travels through a scratch register. Memory-to-memory doesn't exist; every store is compute-into-register, then
sw. When you read a target, find the store, then trace its register backwards to see what was computed.
v0 never appears. The function is void — its result leaves through a0's pointee, not the return register. A function whose listing has no write to v0 before jr ra returns nothing; the pointer parameter is the delivery route. Game code does this everywhere: "fill in this struct", "write the answer here".
The target computes one value from its other arguments and stores it through the first. Read the compute line's mnemonic to see the operation.
Your task
Write func_803e224c to reproduce the target assembly.