-
Notifications
You must be signed in to change notification settings - Fork 8
/
6809_ASUM8.s
74 lines (73 loc) · 1.65 KB
/
6809_ASUM8.s
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
; Title Array Summation
; Name: ASUM8
;
; Purpose: Sum the elements of an array,
; yielding a 16 bit result.
; Maximum size is 255 byte-length elements.
;
; Entry: Register X = Base address of array
; Register A = Size of array in bytes
;
; Exit: Register D = Sum
;
; Registers Used: A,B,CC,X,Y
;
; Time: Approximately 16 cycles per element plus
; 26 cycles overhead
;
; Size: Program 18 bytes
;
; TEST ARRAY LENGTH
; EXIT WITH SUM = 0 IF ARRAY HAS ZERO ELEMENTS
;
ASUM8:
TFR A,B ; SAVE ARRAY LENGTH IN B
CLRA ; EXTELND ARRAY LENGTH TO 16 BITS
TSTB ; CHECK IF ARRAY LENGTH IS ZERO
BEQ EXITAS ; BRANCH (EXIT) IF ARRAY LENGTH IS
; ZERO SUM IS ZERO IN THIS CASE
;
; ADD BYTE-LENGTH ELEMENTS TO LOW BYTE OF SUM ONE AT A TIME
; ADD CARRIES TO HIGH BYTE OF SUM
;
TFR D,Y ; SAVE ARRAY LENGTH IN Y
CLRB ; START SUM AT ZERO (REMEMBER A IS ALREADY ZERO)
;
SUMLP: ADDB ,X+ ; ADD NEXT ELEMENT TO LOW BYTE OF SUM
ADCA #0 ; ADD CARRY TO HIGH BYTE OF SUM
LEAY -1,Y ; CONTINUE THROUGH ALL ELEMENTS
BNE SUMLP
EXITAS:
RTS
;
; SAMPLE EXECUTION
;
SC6A:
LDX #BUF ; GET BASE ADDRESS OF BUFFER
LDA BUFSZ ; GET BUFFER SIZE IN BYTES
JSR ASUM8 ; SUM ELEMENTS IN BUFFER
; SUM OF TEST DATA IS 07F8 HEX,
; REGISTER D = 07F8H
BRA SC6A ; LOOP FOR ANOTHER TEST
;
; TEST DATA, CHANGE FOR OTHER VALUES
;
SIZE: EQU $10 ; SIZE OF BUFFER IN BYTES
BUFSZ: FCB SIZE ; SIZE OF BUFFER IN BYTES
BUF: FCB 0 ; BUFFER
FCB $11 ; DECIMAL ELEMENTS ARE 0,17,34,51,68
FCB $22 ; 85,102,119,135,153,170,187,204
FCB $33 ; 221,238,255
FCB $44
FCB $55
FCB $66
FCB $77
FCB $88
FCB $99
FCB $AA
FCB $BB
FCB $CC
FCB $DD
FCB $EE
FCB $FF
END