diff --git a/README.md b/README.md index 9eb5bdf..bdca7f3 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ macro和repeat内同理,并且这样宏就不会破坏调用前的上下文. | --- | --- | | _CELL_SIZE | 每个Cell的bit数 | | _CELL_MAX | 基于_CELL_SIZE推算出的,Cell中数据的最大值 | +| _ROL_STEP | 用ROR实现ROL时,ROR的次数,通常为_CELL_SIZE - 1 | ## Builtins @@ -59,14 +60,11 @@ macro和repeat内同理,并且这样宏就不会破坏调用前的上下文. | 前缀 | 含义 | | --- | --- | -| bit_unsafe | 最基本的层级,对指定Cell的LSB进行单bit运算且具有破坏性(会清除参数的LSB) | -| bit | 安全的宏,对指定的Unit中,前一个Cell的LSB进行单bit运算,但不会破坏其LSB | -| unsafe | 对指定的整个Cell进行运算,具有破坏性(会清除该Cell) | -| 无前缀 | 安全的宏,对指定Unit中的前一个Cell进行运算,不会破坏该Cell | +| bit | 对指定的Unit中,前一个Cell的LSB进行单bit运算,但不会破坏其LSB | +| distructive | 对指定的区域进行运算,具有破坏性(一般会清除该区域) | +| 无前缀 | 安全的宏,对指定区域进行运算,不会破坏该区域 | ->正如规范中提到的,即使安全宏不会破坏前一个Cell,也会使后一个Cell被清空以作为寄存器.\ ->这是因为安全宏的具体实现就是简单粗暴地把数据拷贝进不同Unit的"后一个Cell"进行计算.\ ->这一点在and.r8asm中体现得尤其明显. +>正如规范中提到的,当安全宏作用于Unit时,即使不会破坏前一个Cell,有时也会使后一个Cell被清空以作为寄存器. ## 流程 diff --git a/asm/add.r8asm b/asm/add.r8asm index 3a43bb8..826f1c0 100644 --- a/asm/add.r8asm +++ b/asm/add.r8asm @@ -1,17 +1,15 @@ %include asm/lib.r8asm -; Macro bit_add +; Macro bit_raw_add ; %1: CellBit A ; %2: CellBit B ; %3: CellBit Ci -; %4: UnitBit S +; %4: CellBit S ; %5: CellBit Co -%macro bit_add 5 -.anchor before_bit_add +; %6: CellBit buf -.tp %4 -stp -.anchor bit_add_buf_1 +%macro bit_raw_add 6 +.anchor before_bit_raw_add .tp %4 biz @@ -94,7 +92,7 @@ biz flb rnz -.tp bit_add_buf_1 +.tp %6 biz flb rnz @@ -106,7 +104,7 @@ biz flb .tp %2 flb - .tp bit_add_buf_1 + .tp %6 flb .tp %3 rnz @@ -120,7 +118,7 @@ biz flb .tp %4 flb - .tp bit_add_buf_1 + .tp %6 flb .tp %2 rnz @@ -132,12 +130,12 @@ biz flb .tp %3 flb - .tp bit_add_buf_1 + .tp %6 flb .tp %1 rnz -.tp bit_add_buf_1 +.tp %6 biz flb .tp %1 @@ -148,42 +146,47 @@ biz flb .tp %4 flb - .tp bit_add_buf_1 + .tp %6 rnz -.tp before_bit_add +.tp before_bit_raw_add %endmacro -; Macro add +; Macro raw_add ; %1: Cell A ; %2: Cell B -; %3: Unit Ci -; %4: Unit S +; %3: Cell Ci +; %4: Cell S ; %5: Cell Co -%macro add 5 -.anchor before_add - +; %6: Cell tmp +%macro raw_add 6 +.anchor before_raw_add +.tp %6 +erase .tp %3 -bit_copy_to_buffer %5 -stp -.anchor add_buf_1 -bit_move_to %5 +bit_copy %6 %5 +.tp %6 +ror %repeat _CELL_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 + bit_raw_add %1 %2 %3 %4 %5 %6 + .tp %5 + bit_distructive_move %3 + .tp %1 + ror + .tp %2 + ror + .tp %4 + ror %endrepeat +.tp %3 +bit_distructive_move %5 +.tp %6 +rol +bit_distructive_move %3 + .tp before_add %endmacro \ No newline at end of file diff --git a/asm/and.r8asm b/asm/and.r8asm index 545bfe0..629b54d 100644 --- a/asm/and.r8asm +++ b/asm/and.r8asm @@ -1,11 +1,11 @@ %include asm/lib.r8asm -; Macro bit_unsafe_and +; Macro bit_distructive_and ; %1: CellBit arg1 ; %2: CellBit arg2 ; %3: CellBit ans -%macro bit_unsafe_and 3 -.anchor before_bit_unsafe_and +%macro bit_distructive_and 3 +.anchor before_bit_distructive_and .tp %3 set_0 .tp %1 @@ -21,20 +21,20 @@ biz set_0 rnz -.tp before_bit_unsafe_and +.tp before_bit_distructive_and %endmacro -; Macro unsafe_and +; Macro distructive_and ; %1: Cell arg1 ; %2: Cell arg2 ; %3: Cell ans -%macro unsafe_and 3 -.anchor before_unsafe_and +%macro distructive_and 3 +.anchor before_distructive_and %repeat _CELL_SIZE - bit_unsafe_and %1 %2 %3 + bit_distructive_and %1 %2 %3 .tp %1 ror .tp %2 @@ -42,7 +42,7 @@ rnz .tp %3 ror %endrepeat -.tp before_unsafe_and +.tp before_distructive_and %endmacro diff --git a/asm/lib.r8asm b/asm/lib.r8asm index 93c87b2..65f35a9 100644 --- a/asm/lib.r8asm +++ b/asm/lib.r8asm @@ -1,27 +1,34 @@ -;lib.r8asm - - +; Macro step +; %1: step_count %macro step 1 stp %1 stp %1 %endmacro +; Macro back +; %1: back_count %macro back 1 btp %1 btp %1 %endmacro +; Macro set_0 +; %this: CellBit operand %macro set_0 0 biz -flb + flb rnz %endmacro +; Macro set_1 +; %this: CellBit operand %macro set_1 0 set_0 flb %endmacro +; Macro erase +; %this: Cell operand %macro erase 0 %repeat _CELL_SIZE set_0 @@ -29,8 +36,9 @@ flb %endrepeat %endmacro - -%macro rol 0 ;Surprise. +; Macro rol +; %this: Cell operand +%macro rol 0 %repeat _ROL_STEP ror %endrepeat @@ -38,63 +46,91 @@ flb -; Macro bit_move_to +; Macro bit_distructive_move +; %this: CellBit data ; %1: CellBit destination -%macro bit_move_to 1 -.anchor before_bit_move_to +%macro bit_distructive_move 1 +.anchor before_bit_distructive_move .tp %1 set_0 -.tp before_bit_move_to +.tp before_bit_distructive_move biz .tp %1 flb - .tp before_bit_move_to + .tp before_bit_distructive_move flb rnz -.tp before_bit_move_to +.tp before_bit_distructive_move +%endmacro + + +; Macro bit_copy +; %this: CellBit data +; %1: CellBit destination +; %2: CellBit buffer + +%macro bit_copy 2 +.anchor before_bit_copy + +.tp %1 +set_0 +.tp %2 +set_0 +.tp before_bit_copy +biz + .tp %1 + flb + .tp %2 + flb + .tp before_bit_copy + flb +rnz +.tp %2 +bit_distructive_move before_bit_copy + +.tp before_bit_copy +%endmacro + + + +; Macro copy +; %this: CellBit data +; %1: CellBit destination +; %2: CellBit buffer + +%macro copy 2 +.anchor before_copy +%repeat _CELL_SIZE + bit_copy %1 %2 + ror + .tp %1 + ror + .tp %2 + ror + .tp before_copy +%endrepeat %endmacro ; Macro bit_copy_to_buffer -; %1: CellBit buffer - +; %this: UnitBit operand +; %1: CellBit 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 -bit_move_to before_bit_copy_to_buffer - -.tp before_bit_copy_to_buffer +.anchor bit_copy_to_buffer_buf_1 +btp +bit_copy bit_copy_to_buffer_buf_1 %1 %endmacro - ; Macro copy_to_buffer -; %1: tmp +; %this: Unit operand +; %1: Cell tmp -%macro copy_to_buffer 1 -.anchor before_copy_to_buffer -%repeat _CELL_SIZE - bit_copy_to_buffer %1 - ror - stp - ror - .tp %1 - ror - .tp before_copy_to_buffer -%endrepeat -%endmacro +%macro copy_to_buffer 0 +stp +.anchor copy_to_buffer_buf_1 +btp +copy copy_to_buffer_buf_1 %1 +%endmacro \ No newline at end of file diff --git a/asm/or.r8asm b/asm/or.r8asm index 41a24ac..1b0212f 100644 --- a/asm/or.r8asm +++ b/asm/or.r8asm @@ -1,10 +1,10 @@ %include asm/lib.r8asm -; Macro bit_unsafe_or +; Macro bit_distructive_or ; %1: CellBit arg1 ; %2: CellBit arg2 ; %3: CellBit ans -%macro bit_unsafe_or 3 -.anchor before_bit_unsafe_or +%macro bit_distructive_or 3 +.anchor before_bit_distructive_or .tp %3 set_0 .tp %1 @@ -22,20 +22,20 @@ biz flb rnz -.tp before_bit_unsafe_or +.tp before_bit_distructive_or %endmacro -; Macro unsafe_or +; Macro distructive_or ; %1: Cell arg1 ; %2: Cell arg2 ; %3: Cell ans -%macro unsafe_or 3 -.anchor before_unsafe_or +%macro distructive_or 3 +.anchor before_distructive_or %repeat _CELL_SIZE - bit_unsafe_or %1 %2 %3 + bit_distructive_or %1 %2 %3 .tp %1 ror .tp %2 @@ -43,7 +43,7 @@ rnz .tp %3 ror %endrepeat -.tp before_unsafe_or +.tp before_distructive_or %endmacro diff --git a/asm/xor.r8asm b/asm/xor.r8asm index cfe9e5c..1eac728 100644 --- a/asm/xor.r8asm +++ b/asm/xor.r8asm @@ -1,11 +1,11 @@ %include asm/lib.r8asm -; Macro bit_unsafe_xor +; Macro bit_distructive_xor ; %1: CellBit arg1 ; %2: CellBit arg2 ; %3: CellBit ans -%macro bit_unsafe_xor 3 -.anchor before_bit_unsafe_xor +%macro bit_distructive_xor 3 +.anchor before_bit_distructive_xor .tp %3 set_0 .tp %1 @@ -23,20 +23,20 @@ biz set_0 rnz -.tp before_bit_unsafe_xor +.tp before_bit_distructive_xor %endmacro -; Macro unsafe_xor +; Macro distructive_xor ; %1: Cell arg1 ; %2: Cell arg2 ; %3: Cell ans -%macro unsafe_xor 3 -.anchor before_unsafe_xor +%macro distructive_xor 3 +.anchor before_distructive_xor %repeat _CELL_SIZE - bit_unsafe_xor %1 %2 %3 + bit_distructive_xor %1 %2 %3 .tp %1 ror .tp %2 @@ -44,7 +44,7 @@ rnz .tp %3 ror %endrepeat -.tp before_unsafe_xor +.tp before_distructive_xor %endmacro