Files
R8Forge/asm/raw_add_bits8.r8asm
T
dsh 32b16eb077 Base addresses instead of 25 parameters
The eight bit adder took 25 macro arguments because every cell address was
passed in.  That was laziness: .tp accepts expressions, so the macro can take
four base addresses and add the offsets itself.

    raw_add_bits8 0 8 16 24     ; A0..7 at 0, B0..7 at 8, S0..7 at 16, carry at 24
    raw_inc_bits8 0 8 16        ; a0..7 at 0, s0..7 at 8, carry at 16

The bodies are unchanged apart from '%1 + 1' style addresses, so the tapes and
the behaviour must be identical, and they are: add8 still 2550 characters, inc8
still 1514.

Re-verified after the change, on the built in machine:
  add8  7 sums (100+50, 128+127, 200+55, 43+199, 255+0, 1+1, 0+0)  7/7
  inc8  7 values (0, 1, 5, 127, 200, 253, 254)                     7/7

Also committed two verify_*.r8asm drivers so the numbers are reproducible.
2026-11-06 23:07:09 +08:00

27 lines
858 B
Plaintext

%include "asm/lib.r8asm"
%include "asm/raw_add_nc4.r8asm"
; 8 位加法器,每一位独占一个干净 cell,不做轮转。
; 只传四个基址,宏自己算偏移:
; %1 = A 基址(A0..A7 占 %1 .. %1+7)
; %2 = B 基址(B0..B7 占 %2 .. %2+7)
; %3 = S 基址(S0..S7 占 %3 .. %3+7)
; %4 = 进位所在的 cell
;
; 每个 cell 始终只放一位(0 或 1),所以 set_0 的前提成立;最高位产生的进位丢掉,
; 前提是 A+B <= 255(不进位输出)。
%macro raw_add_bits8 4
.anchor before_raw_add_bits8
erase %4
bit_add_nc4 %1 %2 %4 %3
bit_add_nc4 %1 + 1 %2 + 1 %4 %3 + 1
bit_add_nc4 %1 + 2 %2 + 2 %4 %3 + 2
bit_add_nc4 %1 + 3 %2 + 3 %4 %3 + 3
bit_add_nc4 %1 + 4 %2 + 4 %4 %3 + 4
bit_add_nc4 %1 + 5 %2 + 5 %4 %3 + 5
bit_add_nc4 %1 + 6 %2 + 6 %4 %3 + 6
bit_add_nc4 %1 + 7 %2 + 7 %4 %3 + 7
.tp before_raw_add_bits8
%endmacro