Two loads, then combine
Up to now every function read a single field. Real code grabs a handful of fields off the same struct and does something with them. The assembly is straightforward: a load per field, all off the same base pointer, then arithmetic to fold them together. Since the base stays in r3, every lwz points at r3 and just changes the displacement.
Take a health struct whose function works out how much health is missing:
typedef struct { int hp; int maxHp; } Health;
int Health_missing(Health* h) {
return h->maxHp - h->hp;
}
lwz r4, 0(r3) # r4 = h->hp (offset 0)
lwz r0, 4(r3) # r0 = h->maxHp (offset 4)
subf r3, r4, r0 # r3 = r0 - r4 = maxHp - hp
blr
The two lwzs park each field in a scratch register, and subf glues them: subf rD, rA, rB is rB − rA. To find which field a load grabbed, look at its offset. To find how they were combined, look at the combining instruction. The one gotcha is ordering: the loads come out in the order the source expression mentions the fields, not necessarily by offset.
Your assembly pulls the same trick on a different struct and uses a different operation. Pair each lwz displacement with a field and rebuild the arithmetic.
Your task
With the Point struct above, write func_80371e38 to reproduce the assembly above.