December 2, 2025
When adding adds drama
Addressing the adding situation – Matt Godbolt
He adds two numbers and the comments explode: is it genius or cheating
TLDR: Matt Godbolt demos adding two numbers via an address-math trick that lets the result land where you want. The thread erupts: fans cheer the teaching, skeptics say x86 isn’t that complex, and a side skirmish debates whether the upper bits must be zero for correctness.
Matt Godbolt just turned a basic “add two numbers” lesson into a full-on comment circus. His twist: instead of a normal add, he uses a chip trick called LEA (a way to do address math) to add numbers while choosing exactly where the result lands — and without messing up other values. Fans swooned. One emulator dev cheered that it’s helping them grok old-school chips like the Game Boy’s Z80. But the moment Matt called x86 “fancy,” a classic nerd turf war lit up. One commenter scoffed that x86 “isn’t even that complex,” invoking ancient machines like VAX like they’re mythic beasts. Meanwhile, another camp flexed micro-knowledge: using LEA doesn’t flip the chip’s “status lights” (CPU flags), which can be clutch later — a subtle tip that had performance heads nodding.
Then came the subplot: the “top bits” fight. Does the system’s rulebook (the ABI — the contract for how programs talk to the computer) force those upper bits to zero, or are they tossed out anyway? One side insists the compiler counts on them being zero; another says that clashes with “we discard them.” Cue: charts, edits, and exasperated sighs. Sprinkle in jokes like “He’s tricking us into learning assembly,” and you’ve got peak code drama. Watch the video if you dare.
Key Points
- •x86 arithmetic instructions typically have two operands, with add modifying the left-hand operand and not allowing a separate destination.
- •Compilers exploit x86’s complex addressing modes and use LEA to compute address expressions without memory access.
- •LEA can be used to effectively perform three-operand addition, choosing a destination register and preserving sources.
- •In the example, LEA calculates a 64-bit address; writing to a 32-bit register discards upper bits, which is acceptable here.
- •Using LEA can save instructions and execute on multiple x86 execution units, and compilers already apply such optimizations.