; .org is ONLY used for internal (assembler/label/alias/...) values, it doesn't output anything! ; So you cannot use .org to place data on a given location. .outfile "isprime.prg" .require "basic_starter.oph.s" .require "kernal.oph.s" .alias check_first 0 .alias check_last 254 main: `lowercase ;`primes_yn check_first, check_last `primes_list check_first, check_last rts .macro primes_list ldx #_1 ; x = check_first _loop: jsr isprimex_print ; do print isprime(x) inx ; ++x cpx #_2 ; while (x <= check_last) bcc _loop beq _loop .macend .macro primes_yn ldx #_1 ; x = check_first _loop: jsr isprimex_yn ; do print isprime(x) inx ; ++x cpx #_2 ; while (x <= check_last) bcc _loop beq _loop .macend ; prints x if it is a prime isprimex_print: jsr isprimex ; a = isprime(x) beq + ; if (a != 0) jsr printx ; print x `printchar 32 ; print " " * rts ; return ; prints "$x Yes\n" when x is prime and "$x No\n" otherwise isprimex_yn: jsr printx ; print x `printchar 32 ; print " " jsr isprimex ; a = isprime(number) beq + ; if (a != 0) `print yes ; print "Yes" `printchar 13 ; print "\n" rts ; return * `print no ; else print "No" `printchar 13 ; print "\n" rts ; return max: .byte 0 ; accumulator is zero if not prime and nonzero otherwise isprimex: .scope cpx #2 ; if (x < 2) // x <= 1 bcc _false ; return False cpx #4 ; if (x < 4) // x <= 3 bcc _true txa ; a = x and #1 ; if (a % 2 == 0) // a & 0b0001 == 0 beq _end ; return False txa ; a = x `mod 3 ; if (a % 3 == 0) beq _end ; return False ldy #6 ; y = 6 stx max ; max = x lsr max ; max /= 2 cpy max ; if (y >= max) bcs _true ; return True _loop: dey ; do --y txa ; a = x `mody ; if (a % y == 0) beq _end ; return False iny ; ++y iny ; ++y txa ; a = x `mody ; if (a % y == 0) beq _end ; return False iny ; ++y iny ; ++y iny ; ++y iny ; ++y iny ; ++y cpy max ; while (y < max) bcc _loop _true: lda #1 ; return True _end: rts _false: lda #0 ; return False rts .scend .charmap 'A, "abcdefghijklmnopqrstuvwxyz" .charmap 'a, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" yes: .byte "Yes",0 no: .byte "No",0