https://github.com/akkartik/mu/blob/master/subx/074print-int-decimal.subx
1
2
3 == code
4
5
6
7
8
9
10
11
12
13
14
15
16 print-int32-decimal:
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 55/push-EBP
48 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
49
50 50/push-EAX
51 51/push-ECX
52 52/push-EDX
53 53/push-EBX
54 57/push-EDI
55
56 b9/copy-to-ECX 0xa/imm32
57
58 68/push 0/imm32/sentinel
59
60 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 0xc/disp8 .
61 3d/compare-EAX-with 0/imm32
62 7d/jump-if-greater-or-equal $print-int32-decimal:read-loop/disp8
63 $print-int32-decimal:negative:
64 f7 3/subop/negate 3/mod/direct 0/rm32/EAX . . . . . .
65 $print-int32-decimal:read-loop:
66
67 99/sign-extend-EAX-into-EDX
68 f7 7/subop/idiv 3/mod/direct 1/rm32/ECX . . . . . .
69
70 81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 0x30/imm32
71
72 52/push-EDX
73
74 3d/compare-EAX-and 0/imm32
75 7f/jump-if-greater $print-int32-decimal:read-loop/disp8
76 $print-int32-decimal:read-break:
77
78 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 0/imm32
79 7d/jump-if-greater-or-equal $print-int32-decimal:write/disp8
80 $print-int32-decimal:push-negative:
81 68/push 0x2d/imm32/-
82 $print-int32-decimal:write:
83
84 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
85
86 8b/copy 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . .
87
88 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX . 1/r32/ECX 0xc/disp8 .
89
90 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 8/disp8 .
91 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 3/index/EBX . 3/r32/EBX 0xc/disp8 .
92 $print-int32-decimal:write-loop:
93
94 58/pop-to-EAX
95
96 3d/compare-EAX-and 0/imm32/sentinel
97 74/jump-if-equal $print-int32-decimal:write-break/disp8
98
99 39/compare 3/mod/direct 1/rm32/ECX . . . 3/r32/EBX . .
100 7d/jump-if-greater-or-equal $print-int32-decimal:abort/disp8
101 $print-int32-decimal:write-char:
102
103 88/copy-byte 0/mod/indirect 1/rm32/ECX . . . 0/r32/AL . .
104
105 41/increment-ECX
106
107 42/increment-EDX
108 eb/jump $print-int32-decimal:write-loop/disp8
109 $print-int32-decimal:write-break:
110
111 89/copy 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . .
112 $print-int32-decimal:end:
113
114 5f/pop-to-EDI
115 5b/pop-to-EBX
116 5a/pop-to-EDX
117 59/pop-to-ECX
118 58/pop-to-EAX
119
120 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
121 5d/pop-to-EBP
122 c3/return
123
124 $print-int32-decimal:abort:
125
126
127 68/push "print-int32-decimal: out of space\n"/imm32
128 68/push 2/imm32/stderr
129
130 e8/call _write/disp32
131
132 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
133
134 bb/copy-to-EBX 1/imm32
135 b8/copy-to-EAX 1/imm32/exit
136 cd/syscall 0x80/imm8
137
138
139 test-print-int32-decimal:
140
141
142
143
144 68/push _test-stream/imm32
145
146 e8/call clear-stream/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
149
150
151 68/push 9/imm32
152 68/push _test-stream/imm32
153
154 e8/call print-int32-decimal/disp32
155
156 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
157
158
159 68/push "F - test-print-int32-decimal"/imm32
160 68/push "9"/imm32
161 68/push _test-stream/imm32
162
163 e8/call check-stream-equal/disp32
164
165 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
166
167 c3/return
168
169 test-print-int32-decimal-zero:
170
171
172
173
174 68/push _test-stream/imm32
175
176 e8/call clear-stream/disp32
177
178 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
179
180
181 68/push 0/imm32
182 68/push _test-stream/imm32
183
184 e8/call print-int32-decimal/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
187
188
189 68/push "F - test-print-int32-decimal-zero"/imm32
190 68/push "0"/imm32
191 68/push _test-stream/imm32
192
193 e8/call check-stream-equal/disp32
194
195 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
196
197 c3/return
198
199 test-print-int32-decimal-multiple-digits:
200
201
202
203
204 68/push _test-stream/imm32
205
206 e8/call clear-stream/disp32
207
208 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
209
210
211 68/push 0xa/imm32
212 68/push _test-stream/imm32
213
214 e8/call print-int32-decimal/disp32
215
216 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
217
218
219 68/push "F - test-print-int32-decimal-multiple-digits"/imm32
220 68/push "10"/imm32
221 68/push _test-stream/imm32
222
223 e8/call check-stream-equal/disp32
224
225 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
226
227 c3/return
228
229 test-print-int32-decimal-negative:
230
231
232
233
234 68/push _test-stream/imm32
235
236 e8/call clear-stream/disp32
237
238 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
239
240
241 68/push -9/imm32
242 68/push _test-stream/imm32
243
244 e8/call print-int32-decimal/disp32
245
246 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
247 +-- 26 lines: #? # dump _test-stream ---------------------------------------------------------------------------------------------------------------------
273
274
275 68/push "F - test-print-int32-decimal-negative"/imm32
276 68/push "-9"/imm32
277 68/push _test-stream/imm32
278
279 e8/call check-stream-equal/disp32
280
281 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
282
283 c3/return
284
285 test-print-int32-decimal-negative-multiple-digits:
286
287
288
289
290 68/push _test-stream/imm32
291
292 e8/call clear-stream/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
295
296
297 68/push -0xa/imm32
298 68/push _test-stream/imm32
299
300 e8/call print-int32-decimal/disp32
301
302 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
303
304
305 68/push "F - test-print-int32-decimal-negative-multiple-digits"/imm32
306 68/push "-10"/imm32
307 68/push _test-stream/imm32
308
309 e8/call check-stream-equal/disp32
310
311 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
312
313 c3/return
314
315