cms.s 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. .define Cms
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine compares two groups of bytes, bit for bit.
  8. ! The groups can consist of 2 or 4 bytes. This number is in
  9. ! register Y.
  10. ! The address of the first group is stored in zeropage locations
  11. ! ADDR and ADDR+1, the address of the second group in ADDR+2 and ADDR+3
  12. ! The routine returns a 0 on equality, a 1 otherwise.
  13. Cms:
  14. lda SP+2
  15. ldx SP+1
  16. sta ADDR ! address of first group (lowbyte)
  17. stx ADDR+1 ! address of second group (highbyte)
  18. clc
  19. tya
  20. adc SP+2
  21. sta SP+2
  22. sta ADDR+2 ! address of second group (lowbyte)
  23. txa
  24. adc #0
  25. sta ADDR+3 ! address of second group (highbyte)
  26. tax
  27. clc
  28. tya
  29. adc SP+2
  30. sta SP+2 ! new stackpointer (lowbyte)
  31. txa
  32. adc #0
  33. sta SP+1 ! new stackpointer (highbyte)
  34. 1: dey
  35. lda (ADDR),y ! get byte first group
  36. cmp (ADDR+2),y ! compare bit for bit with byte second group
  37. bne 2f
  38. tya
  39. bne 1b
  40. lda #0 ! both groups are equal
  41. tax
  42. rts
  43. 2: lda #0 ! there is a difference between the groups
  44. ldx #1
  45. rts