Files
R8Forge/drv/puts_dyn.r8asm
dsh a1f88e3d25 asm: raw_puts_dyn -- print a buffer whose length is only known at run time
A terminal has to echo the line the user just typed, and that length is a cell, not
a constant; clb_puts cannot do it because .tp takes a literal address.  So this one
walks MAX compile time slots and decides per slot whether to print: CNT starts as a
copy of LEN, clb_nonzero turns "CNT != 0" into the flag F, and the print happens
inside `biz F` with the countdown *inside* the guarded body as well.

That last detail is the whole bug this round: with clb_dec_ip outside the guard, a
CNT of 0 wrapped to 2047 on the first skipped cell and the rest of the buffer came
out (LEN=0 printed E F G H).  The fix is also why the driver covers LEN = 3, 0 and
8 -- the zero case is what caught it.

  drv/puts_dyn.r8asm   13376 chars, out 65 66 67 65 66 67 68 69 70 71 72 (ABC, nothing, ABCDEFGH)
  reference machine    "ABCABCDEFGH"     6306 steps

Also learnt: `copy` takes two arguments (%this is the source), and it wants a clean
buffer -- the first version passed three and then reused a dirty T, which showed up
as a countdown that started from the wrong value.

Not in asm/test.r8asm: an 8 slot version costs thousands of characters and the
flagship is about a thousand under the 65536 limit.  SPEC 5.3 records the contract
and that exception; the macro count is 53.
2026-11-17 20:11:01 +08:00

22 lines
379 B
Plaintext

%include "asm/puts_dyn.r8asm"
; raw_puts_dyn 单点验证:MSG 八格放 A..H,分别按 LEN = 3 / 0 / 8 打。
; out 65 66 67 65 66 67 68 69 70 71 72
.var MSG 10
.var LEN 20
.var CNT 21
.var F 22
.var T 23
%for k 8
load MSG+k 65+k
%endfor
load LEN 3
raw_puts_dyn MSG 8 LEN CNT F T
load LEN 0
raw_puts_dyn MSG 8 LEN CNT F T
load LEN 8
raw_puts_dyn MSG 8 LEN CNT F T