2474
|
1 ***************************************
|
|
2
|
|
3 * Subroutine to convert binary number to roman numerals
|
|
4
|
|
5 * OTHER MODULES NEEDED: none
|
|
6
|
|
7 * ENTRY: D=number to convert
|
|
8 * X=start of buffer (20 bytes)
|
|
9
|
|
10
|
|
11 * EXIT: all registers preserved
|
|
12
|
|
13 * Note: the buffer should be set to 20 bytes. This permits the
|
|
14 * longest possible number to be converted without a buffer overflow.
|
|
15 * This routine trunates any numbers >8191 to ensure that no number
|
|
16 * is longer than 19 characters (plus null terminator).
|
|
17 * The number 7888 converts to a 19 character string. To permit larger
|
|
18 * number conversions one could delete the anda #%00011111 statement.
|
|
19
|
|
20 * This routine has been converted from the BASIC09 sample in
|
|
21 * the Basic09 Reference Manual (Microware) page a-3.
|
|
22
|
|
23 nam Binary to Roman numberal conversion
|
|
24 ttl Assembler Library Module
|
|
25
|
|
26
|
|
27 psect BINROM,0,0,0,0,0
|
|
28
|
|
29
|
|
30 BIN_ROM:
|
|
31 pshs d,x,y,u
|
|
32
|
|
33 leau nums,pcr number conversion table
|
|
34 clr ,-s counter on stack
|
|
35 lda 1,s restore value
|
|
36 anda #%00011111 ensure no value>8191 permitted
|
|
37
|
|
38 roman1
|
|
39 cmpd ,u
|
|
40 blo roman2
|
|
41 leay chars,pcr
|
|
42 bsr addchar
|
|
43 subd ,u
|
|
44 bra roman1
|
|
45
|
|
46 roman2
|
|
47 pshs d
|
|
48 ldd ,u
|
|
49 subd 2,u
|
|
50 cmpd ,s
|
|
51 puls d
|
|
52 bhi roman3
|
|
53
|
|
54 leay subs,pcr
|
|
55 bsr addchar
|
|
56 leay chars,pcr
|
|
57 bsr addchar
|
|
58 subd ,u
|
|
59 addd 2,u
|
|
60
|
|
61 roman3
|
|
62 leau 4,u next pair of values
|
|
63 pshs d
|
|
64 inc 2,s counter
|
|
65 lda 2,s
|
|
66 cmpa #7 done?
|
|
67 puls d
|
|
68 bne roman1 no, do more
|
|
69
|
|
70 puls a
|
|
71 clr ,x null terminator
|
|
72
|
|
73 puls d,x,y,u,pc
|
|
74
|
|
75 addchar
|
|
76 pshs d
|
|
77 lda 4,s get loop count
|
|
78 lda a,y get char
|
|
79 sta ,x+
|
|
80 puls d,pc
|
|
81
|
|
82 nums fdb 1000,100
|
|
83 fdb 500,100
|
|
84 fdb 100,10
|
|
85 fdb 50,10
|
|
86 fdb 10,1
|
|
87 fdb 5,1
|
|
88 fdb 1,0
|
|
89
|
|
90 chars fcc /MDCLXVI/
|
|
91 subs fcc /CCXXII/
|
|
92
|
|
93 endsect
|
|
94
|