and.s 918 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. .define And
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine performs the logical and on two groups of
  8. ! atmost 254 bytes. The number of bytes is in register Y.
  9. ! The two groups are on the stack.
  10. ! First the value of the stackpointer is saved in zeropage
  11. ! locations ADDR, ADDR+1. Then an offset of Y is added
  12. ! and stored in ADDR+2, ADDR+3.
  13. ! The result is pushed back on the stack.
  14. And:
  15. lda SP+1
  16. sta ADDR+1 ! address of first group (lowbyte)
  17. lda SP+2
  18. sta ADDR ! address of first group (highbyte)
  19. clc
  20. tya
  21. adc SP+2
  22. sta SP+2 ! new stackpointer (lowbyte)
  23. sta ADDR+2 ! stackpointer + Y (lowbyte)
  24. lda #0
  25. adc SP+1
  26. sta SP+1 ! new stackpointer (highbyte)
  27. sta ADDR+3 ! stackpointer + Y (highbyte)
  28. 1: dey
  29. lda (ADDR),y ! get byte first group
  30. and (ADDR+2),y ! perform logical and with second group
  31. sta (ADDR+2),y ! push result on real_stack
  32. tya
  33. bne 1b ! do it n times
  34. rts