Summary Files Commits Branches @commit @diff @stats
path: root / isprime / kernal.oph.s
diff options
context:
space:
mode:
Commitcf970656bbca915938104a83290a358ba3c4bf17 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-08-01 11:41:52 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-08-01 11:41:52 +0300
Files362b9155379f51afc0ee6904d0370a37217d8799 /isprime/kernal.oph.s
c64-programs-cf970656bbca915938104a83290a358ba3c4bf17.tar
c64-programs-cf970656bbca915938104a83290a358ba3c4bf17.tar.gz
c64-programs-cf970656bbca915938104a83290a358ba3c4bf17.zip
Parent6d08ffeee63a9b4d114542eb9ee59589eed573d2 (diff)
feat(isprime): Implemented prime checking loop
1 files changed, 27 insertions, 2 deletions
-rw-r--r--isprime/kernal.oph.s29
diff --git a/isprime/kernal.oph.s b/isprime/kernal.oph.s
index b39d212..5dda4a4 100644
--- a/isprime/kernal.oph.s
+++ b/isprime/kernal.oph.s
@@ -14,9 +14,15 @@
tax
.macend
-printx:
+.macro printm
+ lda _1
+ jsr printa
+.macend
+
+printx: txa ; a = x
+
+printa:
.scope
- txa ; a = x
cmp #10 ; if (a < 10)
bcc _1digit
cmp #100 ; if (a < 100)
@@ -59,6 +65,25 @@ _end:
buffer: .byte 0
+; a = a % MemoryAddress
+.macro modm
+ cmp _1 ; if (a < _1) return
+ bcc _end
+
+ sec ; carry = 1
+_loop: sbc _1 ; do a -= _1 + !carry
+ beq _end ; if (a == 0) break
+ cmp _1 ; while (a >= _1)
+ bcs _loop
+_end:
+.macend
+
+; a = a % y
+.macro mody
+ sty buffer
+ `modm buffer
+.macend
+
; a = a / _1
.macro div
ora #0 ; The CMP (and friends) instruction changes the carry and zero flag,