forked from jmatzen/leventhal-6809
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6809_Parity.s
127 lines (122 loc) · 2.73 KB
/
6809_Parity.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.macro CLC
ANDCC #$FE
.endm
.macro SEC
ORCC #1
.endm
; Title: Generate and Check Parity
; Name: GEPRTY, CKPRTY
;
; Purpose: GEPRTY generates even parity in bit 7
; for a character.
;
; CKPRTY checks the parity of a byte
;
; Entry:
; GEPRTY data in register A
; CKPRTY data in register A
;
; Exit: GEPRTY data with even parity in bit 7
; in register A
;
; CKPRTY Carry = 0 if parity is even,
; Carry = 1 if parity is odd
;
; Registers Used:
; GEPRTY A, B, CC
; CKPRTY A, B, CC
;
; Time:
; GEPRTY 95 cycles maximum
; CKPRTY 91 cycles maximum
; Size:
; Program 25 bytes
; Data 1 stack byte
;
;
; GENERATE EVEN PARITY
;
GEPRTY:
CLRB ; NUMBER OF 1 BITS = ZERO
ASLA ; DROP DATA BIT 7
PSHS A ; SAVE SHIFTED DATA IN STACK
;
; COUNT 1 BITS UNTIL DATA BECOMES ZERO
;
CNTBIT:
BPL SHIFT ; BRANCH IF NEXT BIT (BIT 7) IS 0
INCB ; ELSE INCREMENT NUMBER OF 1 BITS
SHIFT:
ASLA ; SHIFT DATA LEFT
BNE CNTBIT ; BRANCH IF THERE ARE MORE 1 BITS LEFT
;
; MOVE EVEN PARITY TO BIT 7 OF DATA
;
LSRB ; MOVE EVEN PARITY TO CARRY
; NOTE EVEN PARITY IS BIT 0 OF COUNT
PULS A ; A RESTORE SHIFTED DATA FROM STACK
RORA ; ROTATE TO FORM BYTE WITH EVEN PARITY IN BIT 7
RTS
;
; CHECK PARITY
;
CKPRTY:
CLRB ; NUMBER OF 1 BITS = ZERO
TSTA ; TEST DATA BYTE
;
; COUNT 1 BITS UNTIL DATA BECOMES ZERO
;
BITCNT:
BPL CSHIFT ; BRANCH IF NEXT BIT (BIT 7) IS 0
INCB ; ELSE INCREMENT NUMBER OF 1 BITS
CSHIFT:
ASLA ; SHIFT DATA LEFT
BNE BITCNT ; BRANCH IF THERE ARE MORE 1 BITS LEFT
;
; MOVE PARITY TO CARRY
;
LSRB ; MOVE PARITY TO CARRY
; NOTE PARITY IS BIT 0 OF COUNT
RTS
;
; SAMPLE EXECUTION:
;
; GENERATE PARITY FOR VALUES FROM 0..127
; AND STORE THEM IN BUFFER 1
;
SC8C:
LDX #BUFR1 ; GET BASE ADDRESS OF BUFFER
CLRA ; START DATA AT ZERO
GPARTS:
PSHS A ; SAVE DATA IN STACK
JSR GEPRTY ; ENERATE EVEN PARITY
PULS B ;
STA B,X ; SAVE VALUE WITH EVEN PARITY
TFR B,A ; RETURN DATA VALUE TO A
INCA ; ADD 1 TO DATA VALUE
CMPA #128 ; HAVE WE REACHED HIGHEST VALUE?
BNE GPARTS ; BRANCH IF NOT DONE
;
; CHECK PARITY FOR ALL BYTES IN BUFFER
; CARRY = 1 IF ROUTINE FINDS A PARITY ERROR AND REGISTER
; X POINTS TO THE BYTE WITH THE ERROR
; CARRY = 0 IF ROUTINE FINDS NO PARITY ERRORS
;
LDX #BUFR1 ; GET BASE ADDRESS OF BUFFER
LDA #129 ; CHECK 128 BYTES
PSHS A ; SAVE COUNT ON STACK
CPARTS:
DEC ,S ; DECREMENT COUNT
BEQ CPEXIT ; EXIT IF ALL BYTES CHECKED
LDA ,X+ ; GET NEXT DATA BYTE
JSR CKPRTY ; CHECK PARITY
BCC CPARTS ; IF NO ERROR, CONTINUE THROUGH VALUES
LEAX -1,X ; PARITY ERROR MAKE - X POINT TO IT
CPEXIT:
LEAS 1,S ; REMOVE COUNT BYTE FROM STACK
BRA SC8C ; BRANCH FOR ANOTHER TEST
;
; DATA SECTION
;
BUFR1 RMB 128 ; BUFFER FOR DATA VALUES WITH EVEN PARITY
END