Files
R8Forge/src
dsh 91e3fed537 r8asm %for: repetition with a loop variable
clb_digits needed to name a different cell every round, which %rep cannot do: it
copies identical text N times and has no loop variable, and there is no %if
either, so the three shift steps were spelled out by hand and the macro was
only correct for 11 bit cells.

    %for k 3            ; k is 0, 1, 2 inside the body
        step k
    %endfor

%for <name> <count> binds <name> to 0..count-1 as a compile time constant that
any expression can use: %rep counts, .tp targets, macro arguments.  The loop
scope is a copy of the current scope plus the name, so a %for inside a macro
body still sees that macro's %1, %2, ...  %rep and %for nest in each other
(both closers count as a closer).  %rep itself is untouched.

With it, clb_digits lost its hardcoded chain: the digit count, the shift count
and now the constant builds (tails written as _CELL_SIZE - 5 / _CELL_SIZE - 3)
all follow _CELL_SIZE.  Checked at 16 bits with a five cell region: 4660 gave
'0' '4' '6' '6' '0' and 7 gave '0' '0' '0' '0' '7', so the count really did
become five.  65535 hangs in clb_divmod (6553 rounds, over the 5M step budget)
-- that is the divider's O(N/D), not digits.  Back at 11 bits everything is
unchanged: all eleven values, hash 28729, byte_op and docs green.

SPEC 3.5 documents the directive; it is a local extension like %synth.
2026-11-07 18:05:44 +08:00
..