Files
R8Forge/asm
dsh 1f3f453e88 signed: the two two's complement wrappers, with exhaustive sweeps
clb_digits_signed N REG S T F prints '-' (45) and then |N| as the same four
zero padded digits; clb_divmod_signed N D Q R S T1 T2 F is the C style
truncated division (q = trunc(n/d), r = n - q*d, remainder follows the
dividend).  Both are wrappers: clb_digits / clb_divmod still do the work, so
the tape only grows by the sign handling -- 572 characters for the display
(12151 vs 11579 in the same driver layout) and 1191 for the division
(6018 vs 4827).

The sign bit is read with rol + bit_copy + ror, 49 characters.  clb_bit_mov is
deliberately NOT used: it eats the source bit, so N comes back as N - HALF and
1024 -- whose magnitude 1024 only fits the unsigned range -- prints as 0000.
A clb_sub_nc against a HALF constant was the other candidate: 765 characters
for the call plus ~60 for the constant cell.

A flag has to outlive the block that consumes it, because biz/rnz only exit
once the body clears the condition bit.  So sign(N) is moved into T2, sign(D)
into F, and the remainder block flips F into sign(N)^sign(D) on its way out;
a single conditional negation of the quotient then carries the xor.  The
negation scratch is S+6: the only cell in S with a "clean on entry" contract,
and clb_neg_ip leaves it zero again for clb_divmod.

Verified by r8forge_byte_op_test: all 2048 values for the display (worst
117606 steps) and 4202 division pairs -- every |a|,|b| <= 32 plus the
0/+-1/+-1023/+-1024 boundary combinations -- compared against C's / and %.
examples/signed_demo.r8asm is the single point regression that runs as a
program (the flagship cannot carry them: +12.1k / +5.6k on a 62351 tape).
2026-11-18 21:13:52 +08:00
..