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.
42 lines
1.1 KiB
Plaintext
42 lines
1.1 KiB
Plaintext
%include "asm/lib.r8asm"
|
|
|
|
; 忽略进位的自增切片,3 个 cell:
|
|
; p1..p3 = a, 进位(进->出), s
|
|
;
|
|
; 目标:s = a^Ci,进位 = a&Ci,a 结束为 0。
|
|
; 表由定义直接算出:(a,Ci) = (0,0)->0、(1,0)->4、(0,1)->4、(1,1)->2,
|
|
; 也就是只落在「进位」和 s 这两位。s 的初值不影响结果,所以 8 项是这 4 项重复两遍。
|
|
%synth bit_inc_nc3_synth
|
|
params 3
|
|
stat 0 4 4 2 0 4 4 2
|
|
metric flat
|
|
%endsynth
|
|
|
|
%macro bit_inc_nc3 3
|
|
.tp %3
|
|
set_0
|
|
bit_inc_nc3_synth %1 %2 %3
|
|
%endmacro
|
|
|
|
; 8 位自增,每位一个干净 cell,只传三个基址:
|
|
; %1 = a 基址(a0..a7),%2 = s 基址(s0..s7),%3 = 进位
|
|
;
|
|
; inc 就是 +1,所以进位初值为 1;最后一位产生的进位丢掉,前提是 a < 255。
|
|
%macro raw_inc_bits8 3
|
|
.anchor before_raw_inc_bits8
|
|
erase %3
|
|
; set_1 是不带参数的宏,作用于当前 cell,所以要先 .tp 过去
|
|
.tp %3
|
|
set_1
|
|
|
|
bit_inc_nc3 %1 %3 %2
|
|
bit_inc_nc3 %1 + 1 %3 %2 + 1
|
|
bit_inc_nc3 %1 + 2 %3 %2 + 2
|
|
bit_inc_nc3 %1 + 3 %3 %2 + 3
|
|
bit_inc_nc3 %1 + 4 %3 %2 + 4
|
|
bit_inc_nc3 %1 + 5 %3 %2 + 5
|
|
bit_inc_nc3 %1 + 6 %3 %2 + 6
|
|
bit_inc_nc3 %1 + 7 %3 %2 + 7
|
|
.tp before_raw_inc_bits8
|
|
%endmacro
|