blm.s 983 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. .define Blm, Blmnp
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine copies bytes from one place in memory to
  8. ! another. The source address is in registerpair AX and is stored
  9. ! in zeropage locations ADDR and ADDR+1.
  10. ! The destination address is popped from the stack and stored in
  11. ! zeropage locations ADDR+2 and ADDR+3.
  12. ! The number of bytes to be copied is in register Y (lowbyte) and
  13. ! zeropage location NBYTES+1 (highbyte).
  14. ! The subroutine Blmnp is used when the source and destination
  15. ! addresses are already in zeropage.
  16. Blm:
  17. stx ADDR+2 ! source address (lowbyte)
  18. sta ADDR+3 ! source address (highbyte)
  19. jsr Pop
  20. stx ADDR ! destination address (lowbyte)
  21. sta ADDR+1 ! destination address (highbyte)
  22. Blmnp: ldx NBYTES+1
  23. 1: dey
  24. lda (ADDR),y ! get source byte
  25. sta (ADDR+2),y ! copy to destination
  26. tya
  27. bne 1b
  28. dec ADDR+1 ! 256 bytes copied
  29. dec ADDR+3 ! decrement source and destination address
  30. ldy #0
  31. dex
  32. bne 1b ! do it n times
  33. rts