diff --git a/asm/lib.r8asm b/asm/lib.r8asm index 6699dac..ef5d435 100644 --- a/asm/lib.r8asm +++ b/asm/lib.r8asm @@ -9,35 +9,28 @@ btp %1 %endmacro %macro and 3 -.anchor before_and +; bitwise AND: result[i] = arg1[i] AND arg2[i] +; each %repeat copy processes one bit (LSB after previous rotations) -.tp %1 %repeat _UNIT_SIZE - biz - .tp %2 - biz - .tp %3 - flb - biz - flb - rnz - .tp %2 - rnz - .tp %1 - rnz - ror - .tp %2 - ror - .tp %3 - ror - .tp %1 -%endrepeat + .tp %1 ; → arg1 + biz ; if arg1&1 == 0 → skip (result=0) + .tp %2 ; → arg2 + biz ; if arg2&1 == 0 → skip (result=0) + .tp %3 ; → ans + flb ; set ans LSB = 1 (both bits were 1) + .tp %2 ; ← back to arg2 + flb ; clear arg2 LSB so inner rnz exits + rnz ; arg2 LSB = 0 → exit + .tp %1 ; ← back to arg1 + flb ; clear arg1 LSB so outer rnz exits + rnz ; arg1 LSB = 0 → exit -.tp before_and + .tp %1 ; rotate arg1 for next bit + ror + .tp %2 ; rotate arg2 for next bit + ror + .tp %3 ; rotate ans for next bit + ror %endrepeat - -.tp before_and %endmacro - -out -out \ No newline at end of file diff --git a/include/r8asm/r8asm_parse.hh b/include/r8asm/r8asm_parse.hh index ab16fef..f60a761 100644 --- a/include/r8asm/r8asm_parse.hh +++ b/include/r8asm/r8asm_parse.hh @@ -7,6 +7,7 @@ #include #include #include +#include #include #define EMPTY_CHARS (" \t\n\r\f\v") diff --git a/tests/r8_test.cc.bak b/tests/r8_test.cc.bak new file mode 100644 index 0000000..6a7bcaa --- /dev/null +++ b/tests/r8_test.cc.bak @@ -0,0 +1,18 @@ +#include + +#include "r8asm/r8asm.hh" +#include "r8asm/r8asm_parse.hh" + +int main(int argc, char *argv[]) { + auto lib = read_src("/home/admin/Git/R8ASM/asm/lib.r8asm"); + /* + for (auto i : lib.raw_src) + for (auto j : i) + std::cout << j << ';';*/ + lib.preprocess(); + auto src = read_src("asm/asm.r8asm"); + auto out_tape = r8asm_tape_out(expand_macros(r8asm_preprocess(src))); + for (auto i : out_tape) + std::cout << ROT8_BC_TO_CHAR(i); + return (0); +}