Files
R8Forge/examples
dsh a30a19690b calc: signed display, signed division and a unary minus
'/' now goes through clb_divmod_signed and '.' through clb_digits_signed, so
the accumulator can be negative: "3 5 - ." prints "> -0002", "-5 2 * ."
prints "> -0010" and "-7 -2 / ." prints "> 0003".  Add, subtract and multiply
needed nothing -- mod 2^W arithmetic is already two's complement correct.

The one new piece of state is NEED, "a new operand is expected": expression
start, just settled, just after an operator, just after ','.  A '-' with
NEED == 1 is unary: set NEG, clear ISCMD (so step 3 leaves OP alone), and the
next number is negated in the flush.  NEED == 0 means P already holds an
operand waiting to be settled, so '-' stays the binary minus.

The original plan was "HAVE == 0 means unary", which is wrong: HAVE only says
"digits are being accumulated", so after "2 *" it is 0 too and the minus in
"2 * -5 ." would be parsed as a subtraction.

Two consequences worth knowing: 2047 is now -1, so "2047 3 / ." correctly
prints "> 0000" instead of the old unsigned 0682 (write "1023 3 / ." for 341),
and the printable range is -1024..1023.  The tape grows 59519 -> 62624
characters: the two wrappers plus the NEED/NEG judging.

The file header carries the measured sessions with their step counts and the
three cells the signed macros needed (T1 48, T2 49, SG 50), and examples_test
still checks the "12 34 + ." line.
2026-11-18 21:14:00 +08:00
..