2474
|
1 ************************************************
|
|
2 *
|
|
3 * Binary to decimal conversion
|
|
4
|
|
5 * OTHER MODULES NEEDED: DECTAB$
|
|
6
|
|
7 * ENTRY: X=buffer for ascii string
|
|
8 * D=binary value to convert
|
|
9
|
|
10 * EXIT: all registers (except cc) preserved
|
|
11
|
|
12 * BGP - 04/11/2009 - Fixed issue where BIN_DEC was printing negative
|
|
13 * sign in certain cases. Cleared nega flag to fix issue.
|
|
14
|
|
15 nam Binary to Decimal Conversion
|
|
16 ttl Assembler Library Module
|
|
17
|
|
18
|
|
19 psect BIN_DEC,0,0,0,0,0
|
|
20
|
|
21 vsect
|
|
22 nega rmb 1
|
|
23 endsect
|
|
24
|
|
25 BIN_SDEC:
|
|
26 clr nega,u
|
|
27 tsta
|
|
28 bpl BIN_DEC
|
|
29 sta nega,u
|
|
30 comb
|
|
31 coma
|
|
32 addd #$0001
|
|
33 bra BIN_DEC_COMMON +++ added BGP
|
|
34
|
|
35 BIN_DEC:
|
|
36 clr nega,u +++ added BGP
|
|
37 BIN_DEC_COMMON
|
|
38 pshs a,b,x,y
|
|
39 lda #7 clear out 7 bytes in buffer
|
|
40
|
|
41 bindc1
|
|
42 clr ,x+
|
|
43 deca
|
|
44 bne bindc1
|
|
45 ldx 2,s restore buffer start address
|
|
46 ldd ,s get data
|
|
47 bne bindc2 not 0, do convert
|
|
48 lda #'0
|
|
49 sta ,x
|
|
50 bra bindc8 exit
|
|
51
|
|
52 bindc2
|
|
53 tst nega,u
|
|
54 beq bindc25
|
|
55 pshs a
|
|
56 lda #'-
|
|
57 sta ,x+
|
|
58 puls a
|
|
59 bindc25
|
|
60 leay DECTAB$,pcr point to conversion table
|
|
61 clr ,--s temps, flag 1st dgt not placed
|
|
62
|
|
63 bindc3
|
|
64 clr 1,s current digit=0
|
|
65
|
|
66 bindc4
|
|
67 subd ,y sub table element
|
|
68 bcs bindc5 too far, correct
|
|
69 inc 1,s bump digit
|
|
70 bra bindc4 loop til done
|
|
71
|
|
72 bindc5
|
|
73 addd ,y restore, 1 too many subtracts
|
|
74 pshs a,b save rest of number
|
|
75 lda 3,s get the digit
|
|
76 adda #$30 make it ascii
|
|
77 cmpa #'0 is it zero?
|
|
78 bne bindc6 no, skip
|
|
79 tst 2,s is it 1st digit in string?
|
|
80 beq bindc7 yes, don't do leading 0s
|
|
81
|
|
82 bindc6
|
|
83 inc 2,s indidicate at least 1 digit
|
|
84 sta ,x+ save in buffer
|
|
85
|
|
86 bindc7
|
|
87 leay 2,y next table entry
|
|
88 tst 1,y end of table
|
|
89 puls a,b restore data
|
|
90 bne bindc3 no..loop
|
|
91 leas 2,s
|
|
92
|
|
93 bindc8
|
|
94 puls a,b,x,y,pc restore and return
|
|
95
|
|
96 endsect
|
|
97
|