6502code/move_block.txt
2019-06-13 22:26:24 -07:00

28 lines
998 B
Plaintext

;THIS SUBROUTINE MOVES A BLOCK OF DATA IN MEMORY. THE STARTING
;ADDRESS OF THE DATA IS CONTAINED IN LOCATIONS $40 (LOW ADDRESS
;BYTE) AND $41 (HIGH ADDRESS BYTE). THE STARTING ADDRESS OF
;THE DESTINATION OF THE DATA IS CONTAINED IN LOCATIONS $42 (LOW
;ADDRESS BYTE) AND $43 (HIGH ADDRESS BYTE). THE NUMBER OF BYTES
;TO BE MOVED IS CONTAINED IN LOCATION $44.
MOVE8 LDX $44 /LOAD BYTE COUNT INTO X REGISTER
SEC /CALCULATE MOVE DISPLACEMENT
LDA $42
SBC $40
LDA $43
SBC $41
BMI DISPN /DISPLACEMENT NEGATIVE?
LDY $44 /NO. START MOVE WITH LAST BYTE
CONTI DEY
LDA ($40),Y /LOAD BYTE FROM SOURCE LOCATION
STA ($42),Y / AND STORE IT AT DESTINATION LOCATION
DEX /DECREMENT BYTE COUNT
BNE CONTI /LOOP UNTIL ALL BYTES MOVED
RTS
DISPN LDY #00 /START MOVE WITH FIRST BYTE
CONT2 LDA ($40),Y /LOAD BYTE FROM SOURCE LOCATION
STA ($42),Y / AND STORE IT AT DESTINATION LOCATION
INY /INDEX TO NEXT BYTE
DEX /DECREMENT BYTE COUNT
BNE CONT2 /LOOP UNTIL ALL BYTES MOVED
RTS