1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
**************************************************************************
* 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
|