summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/popcnt.s44
-rw-r--r--test/popcnt2.s41
-rw-r--r--test/stack-frame.s14
3 files changed, 95 insertions, 4 deletions
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 <b0nk@b0nk.xyz>
+.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