This page answers a question that the Bit Lab’s signed-or-unsigned section raises: why does a compiled if use one load instruction for a uint8_t and a different one for an int8_t, when both are a single byte in memory? It is part 8 of From Gates to a Compiled If, after the compare-and-branch page.
What it covers¶
Why a byte has to widen. The processor computes in registers, ARM’s are 32 bits wide, and there is no 8-bit compare, so a byte must be loaded into a full register and 24 bits that were never in memory have to be filled with something.
One byte, both loads. 0x80 through
LDRB(zeros, giving 128) andLDRSB(copies of bit 7, giving −128), then 0x05, on which the two loads agree. The top bit decides.Your pair, live. Two tappable bytes and a
uint8_t/int8_ttoggle. The panel widens both bytes, runs the 32-bit compare as A + NOT B + 1 across 32 columns with the carries shown, reads N Z C V off the result, and says when and why the 32-bit flags differ from the lab’s 8-bit ones while the branch lands the same way.
Next¶
The Bit Lab: the loads inside a compiled
if, beside the C that produced it.The flag drills: widen a byte by hand and check it.