Recomputing a linked tree's cached height #
The nine-instruction program reads the two child caches, treats null children as height zero, computes their maximum plus one, and writes the root cache. The scalar model supplies zero and maximum-plus-one operations with explicit correctness contracts. This is the local height-update step of AVL balancing, not an insertion or balancing algorithm.
Cached scalar height at a subtree root, with the supplied zero for an empty tree.
Six instructions read child caches into data registers one and two. Pointer register two is scratch; a null child keeps the supplied scalar zero.
The cache-read prefix executes before any suffix, preserving the heap and client registers.
Recompute the cursor's height. Data registers one/two and pointer register two are scratch. Null-child loads preserve the initialized scalar zero.
Correct child caches give a correct root cache in nine instructions, including halt. Only the root's selected scalar field, data temporaries one/two and pointer temporary two change. The statement uses structural height; it does not assume that the root cache was already correct.