Full Adder!!!
This commit is contained in:
1 parent
54979833dc
commit
b3e731e9da
9 files changed
+345
-79
No files matched your search
@@ -0,0 +1,87 @@
|
||||
; Macro bit_add
|
||||
; %1: Unit A
|
||||
; %2: Unit B
|
||||
; %3: Unit C
|
||||
; %4: S
|
||||
; %5: Ci
|
||||
%macro bit_add 5
|
||||
.anchor before_bit_add
|
||||
|
||||
.tp %1
|
||||
bit_copy_to_buffer %5
|
||||
stp
|
||||
.anchor bit_add_buf_1
|
||||
.tp %2
|
||||
bit_copy_to_buffer %5
|
||||
stp
|
||||
.anchor bit_add_buf_2
|
||||
|
||||
.tp %3
|
||||
stp
|
||||
.anchor bit_add_buf_3
|
||||
.tp %4
|
||||
set_0
|
||||
.tp %5
|
||||
set_0
|
||||
|
||||
bit_unsafe_xor bit_add_buf_1 bit_add_buf_2 %5
|
||||
.tp %3
|
||||
bit_copy_to_buffer %4
|
||||
bit_unsafe_and bit_add_buf_3 %5 %4
|
||||
.tp %1
|
||||
bit_copy_to_buffer bit_add_buf_3
|
||||
.tp %2
|
||||
bit_copy_to_buffer bit_add_buf_3
|
||||
bit_unsafe_and bit_add_buf_1 bit_add_buf_2 bit_add_buf_3
|
||||
bit_unsafe_or bit_add_buf_3 %4 %5
|
||||
|
||||
.tp %1
|
||||
bit_copy_to_buffer %4
|
||||
.tp %2
|
||||
bit_copy_to_buffer %4
|
||||
bit_unsafe_xor bit_add_buf_1 bit_add_buf_2 %4
|
||||
.tp %3
|
||||
bit_copy_to_buffer bit_add_buf_1
|
||||
bit_unsafe_xor %4 bit_add_buf_3 bit_add_buf_1
|
||||
.tp bit_add_buf_1
|
||||
bit_move_to %4
|
||||
|
||||
.tp before_bit_add
|
||||
%endmacro
|
||||
|
||||
|
||||
; Macro add
|
||||
; %1: Unit A
|
||||
; %2: Unit B
|
||||
; %3: Unit C
|
||||
; %4: S
|
||||
; %5: Unit Ci
|
||||
%macro add 5
|
||||
.anchor before_add
|
||||
|
||||
|
||||
.tp %3
|
||||
bit_copy_to_buffer %5
|
||||
stp
|
||||
.anchor add_buf_1
|
||||
bit_move_to %5
|
||||
|
||||
%repeat _UNIT_SIZE
|
||||
bit_add %1 %2 %5 %4 add_buf_1
|
||||
|
||||
.tp add_buf_1
|
||||
bit_move_to %5
|
||||
|
||||
.tp %1
|
||||
ror
|
||||
.tp %2
|
||||
ror
|
||||
.tp %4
|
||||
ror
|
||||
%endrepeat
|
||||
|
||||
.tp add_buf_1
|
||||
bit_move_to %5
|
||||
|
||||
.tp before_add
|
||||
%endmacro
|
||||
+47
-15
@@ -1,3 +1,29 @@
|
||||
; Macro bit_unsafe_and
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
; %3: ans
|
||||
%macro bit_unsafe_and 3
|
||||
.anchor before_bit_unsafe_and
|
||||
.tp %3
|
||||
set_0
|
||||
.tp %1
|
||||
biz
|
||||
.tp %2
|
||||
biz
|
||||
.tp %3
|
||||
set_1
|
||||
.tp %2
|
||||
set_0
|
||||
rnz
|
||||
.tp %1
|
||||
set_0
|
||||
rnz
|
||||
|
||||
.tp before_bit_unsafe_and
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro unsafe_and
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
@@ -6,21 +32,7 @@
|
||||
.anchor before_unsafe_and
|
||||
|
||||
%repeat _UNIT_SIZE
|
||||
.tp %3
|
||||
set_0
|
||||
.tp %1
|
||||
biz
|
||||
.tp %2
|
||||
biz
|
||||
.tp %3
|
||||
set_1
|
||||
.tp %2
|
||||
set_0
|
||||
rnz
|
||||
.tp %1
|
||||
set_0
|
||||
rnz
|
||||
|
||||
bit_unsafe_and %1 %2 %3
|
||||
.tp %1
|
||||
ror
|
||||
.tp %2
|
||||
@@ -34,6 +46,26 @@
|
||||
|
||||
|
||||
|
||||
; Macro bit_and
|
||||
; %1: Unit arg1
|
||||
; %2: Unit arg2
|
||||
; %3: ans
|
||||
%macro bit_and 3
|
||||
.anchor before_and
|
||||
.tp %1
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_and_buf_1
|
||||
.tp %2
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_and_buf_2
|
||||
bit_unsafe_and bit_and_buf_1 bit_and_buf_2 %3
|
||||
.tp before_and
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro and
|
||||
; %1:unit1
|
||||
; %2:unit2
|
||||
|
||||
+15
-12
@@ -1,17 +1,20 @@
|
||||
step 3
|
||||
.xor 13
|
||||
.anchor arg1
|
||||
step 1
|
||||
.xor 7
|
||||
.anchor arg2
|
||||
back 2
|
||||
.anchor ans
|
||||
.xor 123
|
||||
|
||||
or arg1 arg2 ans
|
||||
.tp 2
|
||||
.xor 23
|
||||
|
||||
.tp arg1
|
||||
.tp 4
|
||||
flb
|
||||
|
||||
add 0 2 4 6 8
|
||||
|
||||
.tp 0
|
||||
out
|
||||
.tp arg2
|
||||
.tp 2
|
||||
out
|
||||
.tp ans
|
||||
.tp 4
|
||||
out
|
||||
.tp 6
|
||||
out
|
||||
.tp 8
|
||||
out
|
||||
+50
-33
@@ -29,48 +29,65 @@ ror
|
||||
%endrepeat
|
||||
%endmacro
|
||||
|
||||
%macro bit_move_to 1
|
||||
.anchor before_bit_move_to
|
||||
.tp %1
|
||||
set_0
|
||||
.tp before_bit_move_to
|
||||
biz
|
||||
.tp %1
|
||||
flb
|
||||
.tp before_bit_move_to
|
||||
flb
|
||||
rnz
|
||||
.tp before_bit_move_to
|
||||
%endmacro
|
||||
|
||||
|
||||
; Macro bit_copy_to_buffer.
|
||||
; %1: tmp
|
||||
|
||||
%macro bit_copy_to_buffer 1
|
||||
.anchor before_bit_copy_to_buffer
|
||||
|
||||
stp
|
||||
set_0
|
||||
.tp %1
|
||||
set_0
|
||||
.tp before_bit_copy_to_buffer
|
||||
biz
|
||||
flb
|
||||
stp
|
||||
flb
|
||||
.tp %1
|
||||
flb
|
||||
.tp before_bit_copy_to_buffer
|
||||
rnz
|
||||
.tp %1
|
||||
biz
|
||||
flb
|
||||
.tp before_bit_copy_to_buffer
|
||||
flb
|
||||
.tp %1
|
||||
rnz
|
||||
|
||||
.tp before_bit_copy_to_buffer
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro copy_to_buffer.
|
||||
; %1: tmp
|
||||
|
||||
%macro copy_to_buffer 1
|
||||
.anchor before_copy_to_buffer
|
||||
stp
|
||||
erase
|
||||
.tp %1
|
||||
erase
|
||||
.tp before_copy_to_buffer
|
||||
%repeat _UNIT_SIZE
|
||||
biz
|
||||
bit_copy_to_buffer %1
|
||||
ror
|
||||
stp
|
||||
set_1
|
||||
ror
|
||||
.tp %1
|
||||
set_1
|
||||
ror
|
||||
.tp before_copy_to_buffer
|
||||
flb
|
||||
rnz
|
||||
.tp before_copy_to_buffer
|
||||
ror
|
||||
stp
|
||||
ror
|
||||
.tp %1
|
||||
ror
|
||||
.tp before_copy_to_buffer
|
||||
%endrepeat
|
||||
|
||||
.tp %1
|
||||
%repeat _UNIT_SIZE
|
||||
biz
|
||||
.tp before_copy_to_buffer
|
||||
set_1
|
||||
.tp %1
|
||||
flb
|
||||
rnz
|
||||
.tp before_copy_to_buffer
|
||||
ror
|
||||
.tp %1
|
||||
ror
|
||||
%endrepeat
|
||||
|
||||
.tp before_copy_to_buffer
|
||||
%endmacro
|
||||
+51
-19
@@ -1,3 +1,31 @@
|
||||
; Macro bit_unsafe_or
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
; %3: ans
|
||||
%macro bit_unsafe_or 3
|
||||
.anchor before_bit_unsafe_or
|
||||
.tp %3
|
||||
set_0
|
||||
.tp %1
|
||||
biz
|
||||
.tp %3
|
||||
flb
|
||||
.tp %1
|
||||
flb
|
||||
rnz
|
||||
.tp %2
|
||||
biz
|
||||
.tp %3
|
||||
set_1
|
||||
.tp %2
|
||||
flb
|
||||
rnz
|
||||
|
||||
.tp before_bit_unsafe_or
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro unsafe_or
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
@@ -6,23 +34,7 @@
|
||||
.anchor before_unsafe_or
|
||||
|
||||
%repeat _UNIT_SIZE
|
||||
.tp %3
|
||||
set_0
|
||||
.tp %1
|
||||
biz
|
||||
.tp %3
|
||||
set_1
|
||||
.tp %1
|
||||
set_0
|
||||
rnz
|
||||
.tp %2
|
||||
biz
|
||||
.tp %3
|
||||
set_1
|
||||
.tp %2
|
||||
set_0
|
||||
rnz
|
||||
|
||||
bit_unsafe_or %1 %2 %3
|
||||
.tp %1
|
||||
ror
|
||||
.tp %2
|
||||
@@ -36,6 +48,26 @@
|
||||
|
||||
|
||||
|
||||
; Macro bit_or
|
||||
; %1: Unit arg1
|
||||
; %2: Unit arg2
|
||||
; %3: ans
|
||||
%macro bit_or 3
|
||||
.anchor before_or
|
||||
.tp %1
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_or_buf_1
|
||||
.tp %2
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_or_buf_2
|
||||
bit_unsafe_or bit_or_buf_1 bit_or:_buf_2 %3
|
||||
.tp before_or
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro or
|
||||
; %1:unit1
|
||||
; %2:unit2
|
||||
@@ -45,11 +77,11 @@
|
||||
|
||||
.tp %1
|
||||
copy_to_buffer %3
|
||||
stp ;Before r8asm_arg_stoi suppports evaluating,it's a compromise.
|
||||
stp ;Before r8asm_arg_stoi suppports evaluating,it's a compromise.
|
||||
.anchor or_buf_1 ;
|
||||
.tp %2
|
||||
copy_to_buffer %3
|
||||
stp ;
|
||||
stp ;
|
||||
.anchor or_buf_2 ;
|
||||
unsafe_or or_buf_1 or_buf_2 ans
|
||||
.tp before_or
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
; Macro bit_unsafe_xor
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
; %3: ans
|
||||
%macro bit_unsafe_xor 3
|
||||
.anchor before_bit_unsafe_xor
|
||||
.tp %3
|
||||
set_0
|
||||
.tp %1
|
||||
biz
|
||||
.tp %3
|
||||
flb
|
||||
.tp %1
|
||||
set_0
|
||||
rnz
|
||||
.tp %2
|
||||
biz
|
||||
.tp %3
|
||||
flb
|
||||
.tp %2
|
||||
set_0
|
||||
rnz
|
||||
|
||||
.tp before_bit_unsafe_xor
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro unsafe_xor
|
||||
; %1: arg1
|
||||
; %2: arg2
|
||||
; %3: ans_unit
|
||||
%macro unsafe_xor 3
|
||||
.anchor before_unsafe_xor
|
||||
|
||||
%repeat _UNIT_SIZE
|
||||
bit_unsafe_xor %1 %2 %3
|
||||
.tp %1
|
||||
ror
|
||||
.tp %2
|
||||
ror
|
||||
.tp %3
|
||||
ror
|
||||
%endrepeat
|
||||
.tp before_unsafe_xor
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
|
||||
; Macro bit_xor
|
||||
; %1: Unit arg1
|
||||
; %2: Unit arg2
|
||||
; %3: ans
|
||||
%macro bit_xor 3
|
||||
.anchor before_xor
|
||||
.tp %1
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_xor_buf_1
|
||||
.tp %2
|
||||
bit_copy_to_buffer %3
|
||||
stp
|
||||
.anchor bit_xor_buf_2
|
||||
bit_unsafe_xor bit_xor_buf_1 bit_xor_buf_2 %3
|
||||
.tp before_xor
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
; Macro xor
|
||||
; %1: Unit arg1
|
||||
; %2: Unit arg2
|
||||
; %3: ans
|
||||
%macro xor 3
|
||||
.anchor before_xor
|
||||
|
||||
.tp %1
|
||||
copy_to_buffer %3
|
||||
stp ;Before r8asm_arg_stoi suppports evaluating,it's a compromise.
|
||||
.anchor xor_buf_1 ;
|
||||
.tp %2
|
||||
copy_to_buffer %3
|
||||
stp ;
|
||||
.anchor xor_buf_2 ;
|
||||
unsafe_xor xor_buf_1 xor_buf_2 ans
|
||||
.tp before_xor
|
||||
%endmacro
|
||||
@@ -37,6 +37,7 @@ enum class r8asm_builtin {
|
||||
ENDMACRO,
|
||||
REPEAT,
|
||||
ENDREPEAT,
|
||||
INCLUDE,
|
||||
};
|
||||
|
||||
using R8Operand = std::variant<std::monostate, r8asm_data, std::string>;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "r8asm/r8asm_parse.hh"
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include "r8asm/r8asm_macro.hh"
|
||||
|
||||
#include <fstream>
|
||||
@@ -15,6 +16,7 @@ std::map<std::string, R8MetaOp> r8asm_parsemap = {
|
||||
{"%endmacro", r8asm_builtin::ENDMACRO},
|
||||
{"%repeat", r8asm_builtin::REPEAT},
|
||||
{"%endrepeat", r8asm_builtin::ENDREPEAT},
|
||||
{"%include",r8asm_builtin::INCLUDE},//TODO:Expand include
|
||||
};
|
||||
|
||||
void r8asm_trim(std::string &str) { // Clean empty chars in the string.
|
||||
|
||||
@@ -7,6 +7,8 @@ int main(int argc, char *argv[]) {
|
||||
auto lib = read_src("asm/lib.r8asm");
|
||||
auto r8and = read_src("asm/and.r8asm");
|
||||
auto r8or = read_src("asm/or.r8asm");
|
||||
auto r8xor = read_src("asm/xor.r8asm");
|
||||
auto r8add = read_src("asm/add.r8asm");
|
||||
/*
|
||||
for (auto i : lib.raw_src)
|
||||
for (auto j : i)
|
||||
@@ -14,6 +16,8 @@ int main(int argc, char *argv[]) {
|
||||
lib.preprocess();
|
||||
r8and.preprocess();
|
||||
r8or.preprocess();
|
||||
r8xor.preprocess();
|
||||
r8add.preprocess();
|
||||
auto src = read_src("asm/asm.r8asm");
|
||||
auto out_tape = r8asm_tape_out(expand_macros(r8asm_preprocess(src)));
|
||||
for (auto i : out_tape)
|
||||
|
||||
Reference in new issue
Block a user