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 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/popcnt.s (limited to 'test/popcnt.s') 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 -- cgit v1.2.3-13-gbd6f