end - start, in elements
C lets you subtract two pointers of the same type, and the result is the number of elements between them — not bytes. The hardware only knows bytes, so the compiler subtracts raw addresses and then divides by the element size. For power-of-two sizes that divide is the signed shift you learned in the arithmetic chapter:
s32 hw_gap(s16 *a, s16 *b) {
return a - b;
}
subu v0, a0, a1 # raw byte distance
sra t6, v0, 1 # ÷ 2 — elements, not bytes
or v0, t6, zero
jr ra
nop
A subu of two incoming pointers feeding an sra is the whole fingerprint. Two readings to take from it:
- The
sra amount is the element size, same encoding as the indexing sll: shift 1 = halfwords, shift 2 = words. The scale-up and scale-down instructions mirror each other across this chapter.
- It's
sra, not srl — a pointer difference is signed (ptrdiff_t), because a - b is negative when a sits below b. You met this exact sra-for-signed-divide reasoning with / 2; here the compiler applies it on your behalf.
You saw a cousin of this in the loops chapter, where subu of two pointers manufactured a span length. Standing alone, it's usually a helper like the target: how many elements sit between these two pointers into the same word array?
Your task
Write func_800aee54 to reproduce the target assembly.