57
|
1 * Convert 32-bits binary number to decimal.
|
|
2 org $400
|
|
3
|
|
4 main lds #$8000
|
|
5 ldx #num1
|
|
6 jsr prtdec
|
|
7 ldx #num2
|
|
8 jsr prtdec
|
|
9 ldx #num3
|
|
10 jsr prtdec
|
|
11 ldx #num4
|
|
12 jsr prtdec
|
|
13 ldx #num5
|
|
14 jsr prtdec
|
|
15 ldx #num6
|
|
16 jsr prtdec
|
|
17 swi
|
|
18
|
|
19
|
|
20 * Print double number (including leading zeros) pointed to by X.
|
|
21 * Number at that location is destroyed by the process.
|
|
22 prtdec jsr bin2bcd ;Convert to bcd
|
|
23 ldx #bcdbuf ;Traverse 5-byte buffer.
|
|
24 ldb #5
|
|
25 stb temp
|
|
26 pdloop lda ,x+
|
|
27 tfr a,b
|
|
28 lsrb
|
|
29 lsrb
|
|
30 lsrb
|
|
31 lsrb ;Extract higher digit from bcd byte.
|
|
32 addb #'0
|
|
33 jsr outch
|
|
34 tfr a,b
|
|
35 andb #15 ;Extract lower digit.
|
|
36 addb #'0
|
|
37 jsr outch
|
|
38 dec temp
|
|
39 bne pdloop
|
|
40 ldb #13 ;output newline.
|
|
41 jsr outch
|
|
42 ldb #10
|
|
43 jsr outch
|
|
44 rts
|
|
45
|
|
46 * Convert 4-byte number pointed to by X to 5-byte (10 digit) bcd.
|
|
47 bin2bcd ldu #bcdbuf
|
|
48 ldb #5
|
|
49 bbclr clr ,u+ ;Clear the 5-byte bcd buffer.
|
|
50 decb
|
|
51 bne bbclr
|
|
52 ldb #4 ;traverse 4 bytes of bin number
|
|
53 stb temp
|
|
54 bbloop ldb #8 ;and 8 bits of each byte. (msb to lsb)
|
|
55 stb temp2
|
|
56 bbl1 rol ,x ;Extract next bit from binary number.
|
|
57 ldb #5
|
|
58 ldu #bcdbuf+5
|
|
59 bbl2 lda ,-u ;multiply bcd number by 2 and add extracted bit
|
|
60 adca ,u ;into it.
|
|
61 daa
|
|
62 sta ,u
|
|
63 decb
|
|
64 bne bbl2
|
|
65 dec temp2
|
|
66 bne bbl1
|
|
67 leax 1,x
|
|
68 dec temp
|
|
69 bne bbloop
|
|
70 rts
|
|
71
|
|
72 * Output character B
|
|
73 outch jsr 3
|
|
74 rts
|
|
75
|
|
76 bcdbuf rmb 5
|
|
77 temp rmb 1
|
|
78 temp2 rmb 1
|
|
79
|
|
80 num1 fdb -1,-1 ; should be 4294967295
|
|
81 num2 fdb 0,0 ; should be 0000000000
|
|
82 num3 fdb 32768,0 ; should be 2147483648
|
|
83 num4 fdb $3b9A,$c9ff ; should be 0999999999
|
|
84 num5 fdb $3b9a,$ca00 ; should be 1000000000
|
|
85 num6 fdb 0,5501 ; should be 0000005501 |