Files
R8Forge/drv/raw_or_byte.r8asm
dsh afd56e7a8c Fix the ROT-8 interpreters: biz / rnz test the low bit
Four interpreters here (tests/synth_test.cc, src/derive.cc and the two I added
earlier: tests/tape_run.cc, tests/byte_add_test.cc) implemented '[' and ']' as
a Brainfuck style "is this whole cell zero" test.  The reference implementation
does not:

    ROT-8-viz src/rot8.c
    rot8_biz: if ((*mem & 1) == 0) skip to just past the matching ']'
    rot8_rnz: if ((*mem & 1) == 1) jump back to the matching '['

That one difference is why every byte level program in the library looked like
an endless loop.  It is invisible in the bit level world -- for a cell holding 0
or 1 the low bit test and the zero test agree -- which is why the synth tables,
asm/test.r8asm and full_add never noticed anything.

Cross checked against the reference before touching anything: the tape our
assembler produces for "A = 128, set_0, B = 3, raw_add" prints 128 3 0 131 0 on
ROT-8-viz/build/rot8_test.exe and hung in our derive.

With the fix, measured:

    raw_add   65536/65536 pairs ok  1647 chars
    raw_and   65536/65536            639
    raw_or    65536/65536            575
    raw_xor   65536/65536            463
    raw_inc   512/512               1214
    asm/fibonacci.r8asm prints 1 1 2 3 5 8 13 21 34 55, exactly what its
    comment claims

So the byte level layer was never broken.  Two commits ago it was declared dead
-- set_0 "only converges on 0 and 1", the bits of a packed byte "unreadable",
raw_add "only survives 0+0" -- entirely on the strength of the broken
interpreters.  AGENTS.md and README.md now say the opposite and keep the wrong
diagnosis as a worked example: when byte level code looks hung, check the
interpreter first.

New:
  tests/byte_op_test.cc + drv/raw_{add,and,or,xor,inc}_byte.r8asm
      exhaustive runtime proof for the byte level library, 0.5 s
  tests/tape_run.cc + r8forge_tape_run
      a second interpreter that runs a .rot8 file directly -- cross checking
      derive is now one command

verify_set_0.r8asm now demonstrates what set_0 really does instead of claiming
it hangs: 255 -> 254, 5 -> 4, 128 -> 128 (it clears the low bit, not the cell).

The one bit per cell layer (byte_add / pack_byte) stays as a documented
alternative: it is correct under the real semantics too, just redundant.
2026-11-07 00:01:25 +08:00

18 lines
293 B
Plaintext

%include "asm/raw_or.r8asm"
; raw_or 的字节级驱动:操作数直接放在 A、B 里,不预置任何常量。
;
; r8forge_derive drv/raw_or_byte.r8asm -2 0=240 2=204
;
; out 依次是 A、B、S。
.var A 0
.var B 2
.var S 4
.var tmp 1
raw_or A B S tmp
output A
output B
output S