************************************************************************** * Parameter Declearation Section * * Export Symbols xdef pgstart ; export 'pgstart' symbol absentry pgstart ; for assembly entry point * Symbols and Macros PORTA equ $0000 ; i/o port A addresses DDRA equ $0002 ; data direction register for PORTA PORTB equ $0001 ; i/o port B addresses DDRB equ $0003 ; data direction register for PORTB ************************************************************************** * Data Section: address used [ $3000 to $30FF ] RAM Memory * org $3000 ; Reserved RAM memory starting address ; for Data for CMPEN 472 class SOURCE ds.b $000C ; 12 Byte source array LENSRC dc.w $000C ; Length of the Source Array DEST ds.b $000C ; 12 Byte destination array LENDST dc.w $000C ; Length of the destination array StackSP dc.w $3100 ; Address of the stack * ************************************************************************** * Program Section: address used [ $3100 to $3FFF ] RAM Memory * org $3100 ; Program start address, in RAM pgstart lds StackSP ; initialize the stack pointer ldaa #1 ; Load 1 into A ldx #SOURCE ; Load the address of SOURCE into X ldy LENSRC ; Load the length of SOURCE into Y fillLoop tbeq Y,doneLoop ; If Y==0, jump to done loop staa 1,X+ ; Copy A into address of X, add 1 to X inca ; Increment A by 1 dey ; Decrement Y by 1 bra fillLoop ; Jump to fillLoop doneLoop jsr memcpy ; Call memcpy bra done ************************************************************************** * Subroutine Section: address used [ $3100 to $3FFF ] RAM Memory * ;************************************************************************* ; memcpy subroutine ; ; This subroutine will copy LENSRC bytes from SOURCE to DEST. ; ; Input: Two addresses, SOURCE and DEST, 1 word length LENSRC ; Output: LENSRC bytes copied from SOURCE to DEST ; Registers in use: D to count the number of bytes copied ; Y to hold the address of the current byte in SOURCE ; X to hold the address of the current byte in DEST ; Memory locations in use: One word, LENSRC, for the length of bytes to copy ; Two arrays, SOURCE & DEST, to copy from SOURCE to DEST ; memcpy pshy ; Save Y to the stack pshx ; Save X to the stack pshd ; Save D to the stack ldy #SOURCE ; Load the address of the source array into Y ldx #DEST ; Load the address of the destination array into X ldd LENSRC ; Load the length of the source array into D loop tbeq D,EXIT ; If d==0, jump to EXIT movb Y,X ; Copy data from address in Y to address in X inx ; Increment X by 1 iny ; Increment Y by 1 subd #1 ; Decrement D by 1 bra loop ; Branch always to loop EXIT puld ; Restore D from the stack pulx ; Restore X from the stack puly ; Restore Y from the stack rts ; Return to caller * ************************************************************************** done end ; Last line of the file