# Nibble calculator ## What this builds A small original CPU, nibble-wide or similarly narrow, and a scientific calculator that runs on it, all in Verilog. A testbench feeds documented operations (add, a chain of stack ops, and optional trig or log) and checks the displayed or register result against a file, with a documented rounding. No FPGA and no handheld are required. This is not a copy of a commercial calculator's firmware. Read `spekkr.inputs.json` first. `digits` and `stack` size the machine. `trig` and `log` add operations. `sim` is the simulator. Display renders are from a dumped register, not a real LCD. ## Out of scope - A real FPGA, a handheld, or a seven-segment board in the checks. - A commercial calculator's ROM or name. - A floating-point certification beyond the file's rounding rules. ## Requirements Each requirement has an id. Checks name the id they cover. ### R1. Operations - The vectors in `fixtures/calc-vectors.json` (including at least add, subtract, multiply, divide, a stack chain, and, if the options are on, a sine and a log) produce the listed results, with the rounding in the file. - A divide-by-zero or an overflow sets a documented error flag and a display state. - Two runs of the testbench hash the same traces. Accept when: every vector matches, the error cases match, and two runs hash equal. ### R2. ISA, files, frames - A short ISA note lists the nibble width, the registers, and the opcodes used by the calculator program. A program dump is in the repo. - Renders: an idle display (zeros or a ready state), an add result, a trig result if on (or a second arithmetic result if off), and an error state. - One command simulates, checks vectors, and writes the renders. No FPGA. Accept when: the command passes for both simulators, and a deliberately wrong vector fixture fails. ### R3. Inputs - Inputs are read from `spekkr.inputs.json`. Values outside the ranges or choices in `design.md` are refused before a netlist, a board or a testbench is built. - Options turn the optional circuits, ports or features in the Inputs table on or off. Accept when: an illegal input is refused by name, and the default input set produces the measurements in `design.md`. ### R4. Checks and report - One command runs the simulation or the testbench, writes the plots or dumps, and compares them to the numbers in `design.md`. - The command works without a physical board, a lab instrument or a network. Accept when: the command passes at the defaults, and fails if a documented value in the netlist or the ROM is corrupted on purpose. ## Verification A testbench of documented operations (arithmetic, stack, optional trig and log, and error cases) matches a vector file, with stated rounding. Display stills are written from a dumped register. No FPGA and no handheld are required. ## Definition of done - Every acceptance check above runs from one command, and all pass at the person's inputs. - A README says how to run the testbench, how rounding is defined, and that a board is optional.