Files
R8Forge/examples
dsh b497bf0637 examples: the desk calculator -- 12 34 + . -> > 0046
The five stage drivers are now one program.  examples/calc.r8asm is a two
register desk calculator: digits build a number, + - * / set the pending
operator, . prints the accumulator (`> 0046` + newline) and , clears it.  EOF (the
0 that inp returns when the input runs out) erases the loop counter, so the loop
ends and the tape simply runs off its end.

    in 12 34 + .   out 62 32 48 48 52 54 10       (> 0046)   314777 steps
    in 2047 3 / .  out 62 32 48 54 56 50 10       (> 0682)   362281
    in 7 6 * .     out 62 32 48 48 52 50 10       (> 0042)   299352
    in 9 4 - .     out 62 32 48 48 48 53 10       (> 0005)   292030
    both of the first two in one session          659759 steps

62585 characters, under ROT-8-viz's 65536 for the first time in this series, so
the whole calculator can be cross-checked against the reference machine later.
tape_run and derive agree, r8forge_examples_test passes all 16 examples, ctest 8/8.

Four deliberate departures from docs/calc.md, each forced by a measurement:

  * settle before loading the new operand, and `.` settles too -- the literal
    order printed 0034 for 12 34 + . because the space arrives before the + and
    overwrites A;  * the operator is one-hot (1 2 4 8) so settlement is four flat
    mutually exclusive biz blocks;  * the loop quota is refilled each round
    (clb_ones can only make _CELL_SIZE ones, 11 here) instead of a fixed 128;
  * three cell moves worth ~24k of tape: clb_undigits scratch 35..45 -> 5..15
    (next to the window it decodes), result/display target 0 -> 20 (adjacent
    scratch makes the %synth blocks shorter), 35..45 reused as one shot flags.

Also found a trap worth remembering: a biz body that ended with `.tp B1; set_0`
(condition cell is FLAG) has net displacement +2, and only on the skipped path
does it desynchronise every later .tp -- the symptom was `-` and `,` sending the
tape into the weeds.  Net displacement 0 on both paths, always.
2026-11-15 16:03:45 +08:00
..