2474
|
1 *****************************************
|
|
2
|
|
3 * Hexadecimal string to BINARY conversion
|
|
4
|
|
5 * OTHER MODULES REQUIRED: TO_UPPER, IS_TERMIN, IS_XDIGIT
|
|
6
|
|
7 * ENTRY: X=start of a hex string terminated by a space,
|
|
8 * comma, CR, or NULL.
|
|
9
|
|
10 * EXIT: D=binary number
|
|
11 * CC carry set iferror (too large, non-numeric)
|
|
12 * Y=terminator position or error char.
|
|
13
|
|
14
|
|
15 nam Convert Hex String to Binary
|
|
16 ttl Assembler Library Module
|
|
17
|
|
18 psect HEX_BIN,0,0,0,0,0
|
|
19
|
|
20
|
|
21 HEX_BIN:
|
|
22 clra init number
|
|
23 clrb
|
|
24 pshs d,x
|
|
25 tfr d,y digit counter
|
|
26
|
|
27 loop
|
|
28 ldb ,x+ get next digit
|
|
29 lbsr TO_UPPER convert to uppercase
|
|
30 lbsr IS_TERMIN end of string?
|
|
31 beq exit yes, go home
|
|
32 lbsr IS_XDIGIT make sure it's valid digit
|
|
33 bne error not 0..9, a..f
|
|
34 cmpb #'9 convert to binary value
|
|
35 bls notAtoF
|
|
36 subb #7 fix a..f
|
|
37 notAtoF
|
|
38 subb #'0 convert to binary 0..15
|
|
39
|
|
40 * now shift the digit to bits 7..4
|
|
41
|
|
42 lslb
|
|
43 lslb
|
|
44 lslb
|
|
45 lslb
|
|
46
|
|
47 * now shift the value in to the result
|
|
48
|
|
49 lda #4 number of bits
|
|
50 l1
|
|
51 lslb digit bit to carry
|
|
52 rol 1,s carry bit to result
|
|
53 rol 0,s
|
|
54 deca done 4?
|
|
55 bne l1 no, loop
|
|
56
|
|
57 leay 1,y number of digits done
|
|
58 cmpy #4
|
|
59 bhi error more than 4
|
|
60 bra loop keep going
|
|
61
|
|
62
|
|
63 exit
|
|
64 clrb clear carry=no error
|
|
65 sty -2,s test y (count)
|
|
66 bne done no digits?
|
|
67
|
|
68 error
|
|
69 clr 0,s
|
|
70 clr 1,s
|
|
71 orcc #1 set carry
|
|
72
|
|
73 done
|
|
74 leay -1,x terminator/error pos
|
|
75 puls d,x,pc
|
|
76
|
|
77 endsect
|
|
78
|
|
79 |