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.
This commit is contained in:
1 parent
1b8ff08455
commit
32b16eb077
4 files changed
+56
-32
No files matched your search
+16
-16
@@ -1,26 +1,26 @@
|
||||
%include "asm/lib.r8asm"
|
||||
%include "asm/raw_add_nc4.r8asm"
|
||||
|
||||
; 8 位加法器,每一位独占一个干净 cell,不做轮转:
|
||||
; %1..%8 = A0..A7
|
||||
; %9..%16 = B0..B7
|
||||
; %17..%24 = S0..S7
|
||||
; %25 = 进位
|
||||
; 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(不进位输出)。
|
||||
; 总共 25 个 cell:每位 3 个 + 1 个进位。
|
||||
%macro raw_add_bits8 25
|
||||
%macro raw_add_bits8 4
|
||||
.anchor before_raw_add_bits8
|
||||
erase %25
|
||||
erase %4
|
||||
|
||||
bit_add_nc4 %1 %9 %25 %17
|
||||
bit_add_nc4 %2 %10 %25 %18
|
||||
bit_add_nc4 %3 %11 %25 %19
|
||||
bit_add_nc4 %4 %12 %25 %20
|
||||
bit_add_nc4 %5 %13 %25 %21
|
||||
bit_add_nc4 %6 %14 %25 %22
|
||||
bit_add_nc4 %7 %15 %25 %23
|
||||
bit_add_nc4 %8 %16 %25 %24
|
||||
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
|
||||
+14
-16
@@ -18,26 +18,24 @@
|
||||
bit_inc_nc3_synth %1 %2 %3
|
||||
%endmacro
|
||||
|
||||
; 8 位自增,每位一个干净 cell:
|
||||
; %1..%8 = a0..a7
|
||||
; %9..%16 = s0..s7
|
||||
; %17 = 进位(初值 1,因为 inc 就是 +1)
|
||||
; 8 位自增,每位一个干净 cell,只传三个基址:
|
||||
; %1 = a 基址(a0..a7),%2 = s 基址(s0..s7),%3 = 进位
|
||||
;
|
||||
; 最后一位产生的进位丢掉:前提是 a < 255。
|
||||
%macro raw_inc_bits8 17
|
||||
; inc 就是 +1,所以进位初值为 1;最后一位产生的进位丢掉,前提是 a < 255。
|
||||
%macro raw_inc_bits8 3
|
||||
.anchor before_raw_inc_bits8
|
||||
erase %17
|
||||
erase %3
|
||||
; set_1 是不带参数的宏,作用于当前 cell,所以要先 .tp 过去
|
||||
.tp %17
|
||||
.tp %3
|
||||
set_1
|
||||
|
||||
bit_inc_nc3 %1 %17 %9
|
||||
bit_inc_nc3 %2 %17 %10
|
||||
bit_inc_nc3 %3 %17 %11
|
||||
bit_inc_nc3 %4 %17 %12
|
||||
bit_inc_nc3 %5 %17 %13
|
||||
bit_inc_nc3 %6 %17 %14
|
||||
bit_inc_nc3 %7 %17 %15
|
||||
bit_inc_nc3 %8 %17 %16
|
||||
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
|
||||
@@ -0,0 +1,13 @@
|
||||
%include "asm/lib.r8asm"
|
||||
%include "asm/raw_add_bits8.r8asm"
|
||||
|
||||
raw_add_bits8 0 8 16 24
|
||||
|
||||
output 16
|
||||
output 17
|
||||
output 18
|
||||
output 19
|
||||
output 20
|
||||
output 21
|
||||
output 22
|
||||
output 23
|
||||
@@ -0,0 +1,13 @@
|
||||
%include "asm/lib.r8asm"
|
||||
%include "asm/raw_inc_bits8.r8asm"
|
||||
|
||||
raw_inc_bits8 0 8 16
|
||||
|
||||
output 8
|
||||
output 9
|
||||
output 10
|
||||
output 11
|
||||
output 12
|
||||
output 13
|
||||
output 14
|
||||
output 15
|
||||
Reference in new issue
Block a user