-
Notifications
You must be signed in to change notification settings - Fork 8
/
6809_BCD2BN.s
53 lines (52 loc) · 1.22 KB
/
6809_BCD2BN.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
; Title: BCD to Binary Conversion
;
; Name: BCD2BN
;
; Purpose: Converts one byte of BCD data to two
; bytes of binary data
;
; Entry: Register A = BCD data
;
; Exit: Register A = Binary data
;
; Registers Used: A,B,CC
;
; Time: 46 cycles
;
; Size: Program 18 bytes
;
; Data: 1 byte on stack
;
BCD2BN: ; SHIFT UPPER DIGIT RIGHT T0 MULTIPLY IT BY 8
;
TFR A,B ; SAVE ORIGINAL BCD VALUE IN B
ANDA #$F0 ; MASK OFF UPPER DIGIT
LSRA ; SHIFT RIGHT 1 BIT
STA ,-S ; SAVE UPPER DIGIT TIMES 8 ON STACK
;
; ADD UPPER DIGIT TIMES 8 T0 LOWER DIGIT
;
ANDB #$0F ; MASK OFF LOWER DIGIT
ADDB ,S+ ; ADD LOWER DIGIT TO STACK VALUE
STB ,-S ; SAVE SUM ON STACK
; SHIFT UPPER DIGIT TIMES 8 RIGHT TWICE
; THE RESULT IS UPPER DIGIT TIMES 2 *
LSRA ; MULTIPLY HIGH DIGIT BY 2
LSRA ;
; UPPER DIGIT * 10 = UPPER DIGIT * 8 + UPPER DIGIT * 2
;
ADDA ,S+ ; ADD STACK VALUE T0 TWICE HIGH DIGIT
RTS
;
; SAMPLE EXECUTION
;
SC1B: ; CONVERT 0 BCD TO 0 HEXADECIMAL
LDA #0
JSR BCD2BN ; A = 00
; CONVERT 99 BCD T0 63 HEXADECIMAL
LDA #$99
JSR BCD2BN ; A = 63H
; CONVERT 23 BCD TO 17 HEXADECIMAL
LDA #$23
JSR BCD2BN ; A = 17H
END