prime.z80 710 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. FracToken:
  2. ld h,b \ ld l,c
  3. call PrimeTest
  4. ld b,0
  5. ld (ThetaPrimeVar),bc
  6. ld b,h \ ld c,l
  7. ret
  8. PrimeTest:
  9. bit 0,l
  10. jr nz,+_
  11. ld bc,2
  12. srl h \ rr l
  13. ret
  14. _:
  15. ld de,PrimeNumbers
  16. ld bc,3501h
  17. PrimeTestLoop:
  18. push bc
  19. push hl
  20. ld a,(de)
  21. ld c,a
  22. call HL_Div_C
  23. pop hl
  24. or a
  25. jr nz,+_
  26. pop de
  27. ret
  28. _:
  29. pop bc
  30. inc de
  31. djnz PrimeTestLoop
  32. scf
  33. ;6 bytes, 24cc
  34. ld a,h
  35. ld h,b
  36. ld b,l
  37. ld l,c
  38. ld c,b
  39. ld b,a
  40. ;3 bytes, 40cc
  41. ; push bc
  42. ; ex (sp),hl
  43. ; pop bc
  44. ret
  45. PrimeNumbers:
  46. .db 3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
  47. .db 101,103,107,109,113,127,131,137,139,149,151,157,163
  48. .db 167,173,179,181
  49. .db 191,193,197,199,211,223,227,229,233,239,241,251