From 1ec19679b3db209429b0897f6ccda6d09d018a70 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 8 Aug 2020 10:28:36 -0400 Subject: Did a ton of stuff. - Changed the file structure of the SuB Suite, so that all variable declarations, symbols, and constants are in a single file. - Moved the C library functionss into a separate file, and made them use stack frames. - Added support for using the emulator's assembler for realtime debugging, to enter it, get in to stepping mode by pressing Ctrl+s, press any other key, then press F1, The reason for having to press some other key before pressing F1 is because it only allows entering the assembler when the keyboard is not ready. - Added the ".res" directive to the emulator's assembler, the ".res" directive tells the assembler to reserve however many bytes specified by the operand. - Fixed some bugs in the emulator's assembler. --- test/popcnt.s | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/popcnt2.s | 41 +++++++++++++++++++++++++++++++++++++++++ test/stack-frame.s | 14 ++++++++++---- 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 test/popcnt.s create mode 100644 test/popcnt2.s (limited to 'test') diff --git a/test/popcnt.s b/test/popcnt.s new file mode 100644 index 0000000..7682653 --- /dev/null +++ b/test/popcnt.s @@ -0,0 +1,44 @@ +; Calculate population count/hamming weight. + +.org $1000 + +popcnt: + ldb #0 ; Reset bit count. + pha.q ; Create a temporary variable. + cmp #0 ; Set the status flags. +@loop: + beq @end ; There are no more one bits left, so we're done. + dec.q sp+1 ; Decrement the temp variable. + dec.q sp+1 ; Decrement the temp variable. + inb ; Increment the bit count. + and.q sp+1 ; AND value with value-1. + sta.q sp+1 ; Place it back in the temp variable. + bra @loop ; Keep looping. +@end: + pla.q ; Pull/Pop the temp variable off the stack. + tba ; Return the bit count. + rts ; End of popcnt. + + +reset: + cps ; Boilerplate reset code. + ldx.w #$FFFF ; + txs ; + and #0 ; Reset A. + tab ; Reset B. + tax ; Reset X. + tay ; Reset Y. +main: + pha.q ; Save A. + jsr popcnt ; Get population count. + tay ; Save it in Y. + pla.q ; Get A back. + inc ; Increment A by one. + bra main ; Keep looping. + + +.org $FFC0 +.qword reset + +a +d diff --git a/test/popcnt2.s b/test/popcnt2.s new file mode 100644 index 0000000..aaa4743 --- /dev/null +++ b/test/popcnt2.s @@ -0,0 +1,41 @@ +; Register only version of popcnt. + +.org $1000 + +popcnt: + ldy #0 ; Reset bit count. + cmp #0 ; Set the status flags. +@loop: + beq @end ; There are no more one bits left, so we're done. + tab ; Place the value in the B register. + deb ; Decrement the temp value by one. + iny ; Increment the bit count. + aba ; AND value with value-1. + bra @loop ; Keep looping. +@end: + tya ; Return the bit count. + rts ; End of popcnt. + + +reset: + cps ; Boilerplate reset code. + ldx.w #$FFFF ; + txs ; + and #0 ; Reset A. + tab ; Reset B. + tax ; Reset X. + tay ; Reset Y. +main: + pha.q ; Save A. + jsr popcnt ; Get population count. + tay ; Save it in Y. + pla.q ; Get A back. + inc ; Increment A by one. + bra main ; Keep looping. + + +.org $FFC0 +.qword reset + +a +d diff --git a/test/stack-frame.s b/test/stack-frame.s index 6e64b86..0f631b9 100644 --- a/test/stack-frame.s +++ b/test/stack-frame.s @@ -1,6 +1,10 @@ ; Testing stack frames. ; Written by mr b0nk 500 +.org $0 +var: + .byte 0 + .org $8000 reset: cps ; @@ -10,16 +14,18 @@ reset: tay ; tax ; tab ; + sta.q var ; start: inc ; pha ; - ldb sp, $1 ; + ldb sp+1 ; pla ; - sta $0 ; + sta var ; + ldy #var ; phy.q ; - ldb (sp, $8) ; + ldb (sp+1) ; ply.q ; - ldb (sp, -$8) ; + ldb (sp-7) ; bra start ; .org $FFC0 -- cgit v1.2.3-13-gbd6f