{"by":"gdevic","descendants":42,"id":48151237,"kids":[48152138,48156864,48151942,48155197,48154608,48155549,48160123,48152436,48154330,48155830,48155046,48157112,48156473,48151258,48153614,48151875],"score":119,"text":"The core question: how did HP&#x27;s scientific calculators actually work at the gate level? That rabbit hole led to building one from scratch.<p>The architectural decision everything else follows from: a decimal calculator should store numbers as BCD — one decimal digit per 4-bit nibble. A standard byte-oriented CPU (Z80, 6502) fights that layout constantly. So I designed a small custom CPU in Verilog where 4 bits is the natural data width and memory is nibble addressable.<p>What the project covers:<p>- Custom CPU: Harvard architecture, 12-bit ISA, 8-state execution \n  FSM, hardware stack guard with a FAULT state for microcode debugging<p>- CORDIC for trig functions, verified to 14 significant digits<p>- Two-pass assembler in Python (~700 lines)<p>- Verilator + Qt framework: same Verilog source runs in simulation, \n  as a desktop GUI debugger, as WebAssembly, and on real hardware<p>- Scripting language on top of the microcode for adding functions \n  without touching hardware<p>- Custom PCB (EasyEDA&#x2F;JLCPCB), battery, charging circuit<p>Write-up: <a href=\"https:&#x2F;&#x2F;baltazarstudios.com\" rel=\"nofollow\">https:&#x2F;&#x2F;baltazarstudios.com</a><p>Hackaday: <a href=\"https:&#x2F;&#x2F;hackaday.com&#x2F;2026&#x2F;05&#x2F;13&#x2F;build-the-cpu-then-build-the-calculator&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;hackaday.com&#x2F;2026&#x2F;05&#x2F;13&#x2F;build-the-cpu-then-build-the...</a>","time":1778865358,"title":"Show HN: A nibble-oriented CPU in Verilog to build a scientific calculator","type":"story","url":"https://github.com/gdevic/FPGA-Calculator"}