Loop N times¶
Problem¶
Run a block of code N times where N is known at assembly time (a compile-time constant).
Code¶
stl.startup
rep(5, i) stl.output_char 'A' + i
stl.output '\n'
stl.loop
Output: ABCDE\n
Walkthrough¶
rep(N, var) bodyis FlipJump’s compile-time loop. It expands its body N times withvarbound to0, 1, 2, …, N-1.Nmust be a constant expression — there is no runtimeforloop at the language level (you build one yourself using conditional branches).'A' + iis an assembly-time expression: at expansion #0 it’s'A', at #1 it’s'B', etc.
Variations¶
Runtime loop (N known only at runtime): use a counter variable + conditional branch.
stl.startup_and_init_all
bit.bit done_flag
counter_loop:
bit.print_dec_uint 8, n
stl.output '\n'
bit.dec 8, n
bit.if 8, n, end, counter_loop
end:
stl.loop
n: bit.vec 8, 5
Loop with index in body — rep supports complex expressions referencing i:
rep(16, i) bit.zero 8, table + i*8*dw