Files
R8Forge/drv/divmod.r8asm
T
dsh 4a5bd836a8 clb_divmod: nine parameters down to four
Complaint received and agreed with: nine cells to pass for a division is not an
interface anybody wants to type.  Two things made it possible to shrink:

  * .tp and macro arguments accept address expressions (measured: .tp A+1
    assembles, and set_0 A+1 expands to .tp A+1 inside the callee).  So the
    four scratch cells can be passed as one block: clb_divmod N D Q S uses S,
    S+1, S+2 and S+3.
  * BUF and X were unnecessary: copy already has sources and destinations to
    spare that are dead at the moment they are needed, and clb_inc_ip can take
    a cell that the probe is about to overwrite.

So the signature is now clb_divmod N D Q S -- three data cells and one scratch
base -- and the tape dropped from 5839 to 4189 characters on the way, because
the scratch cells now sit next to each other and every .tp walk got shorter.

Still correct: all 76 sampled pairs (2047/10 = 204 7, 7/10 = 0 7, 10/10 = 1 0,
1234/100 = 12 34, 999/7 = 142 5, 2047/2047 = 1 0), and the O(N/D) limit is
unchanged.
2026-11-07 16:53:27 +08:00

18 lines
363 B
Plaintext

%include "asm/divmod.r8asm"
; clb_divmod 的驱动:0 号 cell 放被除数、1 号放除数,输出商和余数。
;
; r8forge_derive drv/divmod.r8asm -2 0=2047 1=10 # 204 7
; r8forge_derive drv/divmod.r8asm -2 0=7 1=10 # 0 7(零轮)
;
; out 依次是商、余数。
.var N 0
.var D 1
.var Q 2
.var S 3
clb_divmod N D Q S
output Q
output N