* Main program to test memcopy subroutine. * Assemble & step through this in THRSIM, * watching the memory dump of region $0000, * and comparing it to the dump of $1000. test: LDD #$40 ; Copy 40 bytes LDX #$1000 ; from $1000 (control regs) LDY #$0000 ; to $0000 (internal RAM) BSR memcopy ; Do it! end: BRA end ; Stop here * Copy one region of memory to another. * Inputs: * X = Address of 1st byte of source region. * Y = Address of 1st byte of destination region. * D = Number of bytes to copy. memcopy: CPD #0 ; Compare D to 0. BEQ done ; If D=0, nothing left to copy. PSHA ; Save the MSB of D. LDAA 0,X ; Load next byte to copy. INX ; Go to next source byte. STAA 0,Y ; Store A at destination addr. INY ; Go to next destination byte. PULA ; Restore the MSB of D. SUBD #1 ; Decrement # of bytes left. BRA memcopy ; Repeat. done: RTS ; Return to caller.