Commit | Line | Data |
---|---|---|
4a71579b PC |
1 | .data 256 |
2 | .$($int = 4) | |
3 | C: | |
4 | .c "\nC:" | |
5 | F: | |
6 | .c "\nF:" | |
7 | format: | |
8 | .c "%3d " | |
9 | newline: | |
10 | .c "\n" | |
11 | ||
12 | .code | |
13 | jmpi main | |
14 | ||
15 | name c2f | |
16 | c2f: | |
17 | prolog | |
18 | arg $in | |
19 | ||
20 | allocai $(32 * $int) $index | |
21 | ||
22 | getarg %r2 $in | |
23 | ||
24 | // 32x9*5/+ | |
25 | movi %r0 32 | |
26 | ||
27 | // x9*5/+ | |
28 | stxi_i $index %fp %r0 | |
29 | . $($index = $index + $int) | |
30 | movr %r0 %r2 | |
31 | ||
32 | // 9*5/+ | |
33 | stxi_i $index %fp %r0 | |
34 | . $($index = $index + $int) | |
35 | movi %r0 9 | |
36 | ||
37 | // *5/+ | |
38 | . $($index = $index - $int) | |
39 | ldxi_i %r1 %fp $index | |
40 | mulr %r0 %r1 %r0 | |
41 | ||
42 | // 5/+ | |
43 | stxi_i $index %fp %r0 | |
44 | . $($index = $index + $int) | |
45 | movi %r0 5 | |
46 | ||
47 | // /+ | |
48 | . $($index = $index - $int) | |
49 | ldxi_i %r1 %fp $index | |
50 | divr %r0 %r1 %r0 | |
51 | ||
52 | // + | |
53 | . $($index = $index - $int) | |
54 | ldxi_i %r1 %fp $index | |
55 | addr %r0 %r1 %r0 | |
56 | ||
57 | retr %r0 | |
58 | epilog | |
59 | ||
60 | name f2c | |
61 | f2c: | |
62 | prolog | |
63 | arg $in | |
64 | ||
65 | allocai $(32 * $int) $index | |
66 | ||
67 | getarg %r2 $in | |
68 | ||
69 | // x32-5*9/ | |
70 | stxi_i $index %fp %r0 | |
71 | . $($index = $index + $int) | |
72 | movr %r0 %r2 | |
73 | ||
74 | // 32-5*9/ | |
75 | stxi_i $index %fp %r0 | |
76 | . $($index = $index + $int) | |
77 | movi %r0 32 | |
78 | ||
79 | // -5*9/ | |
80 | . $($index = $index - $int) | |
81 | ldxi_i %r1 %fp $index | |
82 | subr %r0 %r1 %r0 | |
83 | ||
84 | // 5*9/ | |
85 | stxi_i $index %fp %r0 | |
86 | . $($index = $index + $int) | |
87 | movi %r0 5 | |
88 | ||
89 | // *9/ | |
90 | . $($index = $index - $int) | |
91 | ldxi_i %r1 %fp $index | |
92 | mulr %r0 %r1 %r0 | |
93 | ||
94 | // 9/ | |
95 | stxi_i $index %fp %r0 | |
96 | . $($index = $index + $int) | |
97 | movi %r0 9 | |
98 | ||
99 | // / | |
100 | . $($index = $index - $int) | |
101 | ldxi_i %r1 %fp $index | |
102 | divr %r0 %r1 %r0 | |
103 | ||
104 | retr %r0 | |
105 | epilog | |
106 | ||
107 | //----------------------------------------------------------------------- | |
108 | name main | |
109 | main: | |
110 | prolog | |
111 | ||
112 | prepare | |
113 | pushargi C | |
114 | ellipsis | |
115 | finishi @printf | |
116 | movi %v0 0 | |
117 | loopC: | |
118 | prepare | |
119 | pushargi format | |
120 | ellipsis | |
121 | pushargr %v0 | |
122 | finishi @printf | |
123 | addi %v0 %v0 10 | |
124 | blei loopC %v0 100 | |
125 | prepare | |
126 | pushargi F | |
127 | ellipsis | |
128 | finishi @printf | |
129 | movi %v0 0 | |
130 | loopC2F: | |
131 | prepare | |
132 | pushargr %v0 | |
133 | finishi c2f | |
134 | retval %r0 | |
135 | prepare | |
136 | pushargi format | |
137 | ellipsis | |
138 | pushargr %r0 | |
139 | finishi @printf | |
140 | addi %v0 %v0 10 | |
141 | blei loopC2F %v0 100 | |
142 | prepare | |
143 | pushargi newline | |
144 | ellipsis | |
145 | finishi @printf | |
146 | ||
147 | prepare | |
148 | pushargi F | |
149 | ellipsis | |
150 | finishi @printf | |
151 | movi %v0 32 | |
152 | loopF: | |
153 | prepare | |
154 | pushargi format | |
155 | ellipsis | |
156 | pushargr %v0 | |
157 | finishi @printf | |
158 | addi %v0 %v0 18 | |
159 | blei loopF %v0 212 | |
160 | prepare | |
161 | pushargi C | |
162 | ellipsis | |
163 | finishi @printf | |
164 | movi %v0 32 | |
165 | loopF2C: | |
166 | prepare | |
167 | pushargr %v0 | |
168 | finishi f2c | |
169 | retval %r0 | |
170 | prepare | |
171 | pushargi format | |
172 | ellipsis | |
173 | pushargr %r0 | |
174 | finishi @printf | |
175 | addi %v0 %v0 18 | |
176 | blei loopF2C %v0 212 | |
177 | prepare | |
178 | pushargi newline | |
179 | ellipsis | |
180 | finishi @printf | |
181 | ||
182 | ret | |
183 | epilog |