https://github.com/akkartik/mu/blob/master/075print-int-decimal.subx
1
2
3 == code
4
5
6
7
8 print-int32-decimal:
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 55/push-ebp
40 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
41
42 50/push-eax
43 51/push-ecx
44 52/push-edx
45 53/push-ebx
46 57/push-edi
47
48 b9/copy-to-ecx 0xa/imm32
49
50 68/push 0/imm32/sentinel
51
52 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
53 3d/compare-eax-with 0/imm32
54 7d/jump-if->= $print-int32-decimal:read-loop/disp8
55 $print-int32-decimal:negative:
56 f7 3/subop/negate 3/mod/direct 0/rm32/eax . . . . . .
57 $print-int32-decimal:read-loop:
58
59 99/sign-extend-eax-into-edx
60 f7 7/subop/idiv 3/mod/direct 1/rm32/ecx . . . . . .
61
62 81 0/subop/add 3/mod/direct 2/rm32/edx . . . . . 0x30/imm32
63
64 52/push-edx
65
66 3d/compare-eax-and 0/imm32
67 7f/jump-if-> $print-int32-decimal:read-loop/disp8
68 $print-int32-decimal:read-break:
69
70 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 0/imm32
71 7d/jump-if->= $print-int32-decimal:write/disp8
72 $print-int32-decimal:push-negative:
73 68/push 0x2d/imm32/-
74 $print-int32-decimal:write:
75
76 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
77
78 8b/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
79
80 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 2/index/edx . 1/r32/ecx 0xc/disp8 .
81
82 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 3/r32/ebx 8/disp8 .
83 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 3/index/ebx . 3/r32/ebx 0xc/disp8 .
84 $print-int32-decimal:write-loop:
85
86 58/pop-to-eax
87
88 3d/compare-eax-and 0/imm32/sentinel
89 74/jump-if-= $print-int32-decimal:write-break/disp8
90
91 39/compare 3/mod/direct 1/rm32/ecx . . . 3/r32/ebx . .
92 73/jump-if-addr>= $print-int32-decimal:abort/disp8
93 $print-int32-decimal:write-char:
94
95 88/copy-byte 0/mod/indirect 1/rm32/ecx . . . 0/r32/AL . .
96
97 41/increment-ecx
98
99 42/increment-edx
100 eb/jump $print-int32-decimal:write-loop/disp8
101 $print-int32-decimal:write-break:
102
103 89/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
104 $print-int32-decimal:end:
105
106 5f/pop-to-edi
107 5b/pop-to-ebx
108 5a/pop-to-edx
109 59/pop-to-ecx
110 58/pop-to-eax
111
112 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
113 5d/pop-to-ebp
114 c3/return
115
116 $print-int32-decimal:abort:
117
118
119 68/push "print-int32-decimal: out of space\n"/imm32
120 68/push 2/imm32/stderr
121
122 e8/call _write/disp32
123
124 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
125
126 bb/copy-to-ebx 1/imm32
127 b8/copy-to-eax 1/imm32/exit
128 cd/syscall 0x80/imm8
129
130
131 test-print-int32-decimal:
132
133
134
135
136 68/push _test-stream/imm32
137
138 e8/call clear-stream/disp32
139
140 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
141
142
143 68/push 9/imm32
144 68/push _test-stream/imm32
145
146 e8/call print-int32-decimal/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
149
150
151 68/push "F - test-print-int32-decimal"/imm32
152 68/push "9"/imm32
153 68/push _test-stream/imm32
154
155 e8/call check-stream-equal/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
158
159 c3/return
160
161 test-print-int32-decimal-zero:
162
163
164
165
166 68/push _test-stream/imm32
167
168 e8/call clear-stream/disp32
169
170 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
171
172
173 68/push 0/imm32
174 68/push _test-stream/imm32
175
176 e8/call print-int32-decimal/disp32
177
178 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
179
180
181 68/push "F - test-print-int32-decimal-zero"/imm32
182 68/push "0"/imm32
183 68/push _test-stream/imm32
184
185 e8/call check-stream-equal/disp32
186
187 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
188
189 c3/return
190
191 test-print-int32-decimal-multiple-digits:
192
193
194
195
196 68/push _test-stream/imm32
197
198 e8/call clear-stream/disp32
199
200 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
201
202
203 68/push 0xa/imm32
204 68/push _test-stream/imm32
205
206 e8/call print-int32-decimal/disp32
207
208 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
209
210
211 68/push "F - test-print-int32-decimal-multiple-digits"/imm32
212 68/push "10"/imm32
213 68/push _test-stream/imm32
214
215 e8/call check-stream-equal/disp32
216
217 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
218
219 c3/return
220
221 test-print-int32-decimal-negative:
222
223
224
225
226 68/push _test-stream/imm32
227
228 e8/call clear-stream/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
231
232
233 68/push -9/imm32
234 68/push _test-stream/imm32
235
236 e8/call print-int32-decimal/disp32
237
238 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
239 +-- 26 lines: #? # dump _test-stream ---------------------------------------------------------------------------------------------------------------------
265
266
267 68/push "F - test-print-int32-decimal-negative"/imm32
268 68/push "-9"/imm32
269 68/push _test-stream/imm32
270
271 e8/call check-stream-equal/disp32
272
273 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
274
275 c3/return
276
277 test-print-int32-decimal-negative-multiple-digits:
278
279
280
281
282 68/push _test-stream/imm32
283
284 e8/call clear-stream/disp32
285
286 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
287
288
289 68/push -0xa/imm32
290 68/push _test-stream/imm32
291
292 e8/call print-int32-decimal/disp32
293
294 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
295
296
297 68/push "F - test-print-int32-decimal-negative-multiple-digits"/imm32
298 68/push "-10"/imm32
299 68/push _test-stream/imm32
300
301 e8/call check-stream-equal/disp32
302
303 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
304
305 c3/return
306
307 is-decimal-digit?:
308
309 55/push-ebp
310 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
311
312 51/push-ecx
313
314 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 8/disp8 .
315
316 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0x30/imm32
317 7c/jump-if-< $is-decimal-digit?:false/disp8
318
319 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0x39/imm32
320 7e/jump-if-<= $is-decimal-digit?:true/disp8
321
322 $is-decimal-digit?:false:
323 b8/copy-to-eax 0/imm32/false
324 eb/jump $is-decimal-digit?:end/disp8
325 $is-decimal-digit?:true:
326 b8/copy-to-eax 1/imm32/true
327 $is-decimal-digit?:end:
328
329 59/pop-to-ecx
330
331 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
332 5d/pop-to-ebp
333 c3/return
334
335 test-is-decimal-digit-below-0:
336
337
338 68/push 0x2f/imm32
339
340 e8/call is-decimal-digit?/disp32
341
342 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
343
344
345 68/push "F - test-is-decimal-digit-below-0"/imm32
346 68/push 0/imm32/false
347 50/push-eax
348
349 e8/call check-ints-equal/disp32
350
351 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
352 c3/return
353
354 test-is-decimal-digit-0-to-9:
355
356
357 68/push 0x30/imm32
358
359 e8/call is-decimal-digit?/disp32
360
361 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
362
363
364 68/push "F - test-is-decimal-digit-at-0"/imm32
365 68/push 1/imm32/true
366 50/push-eax
367
368 e8/call check-ints-equal/disp32
369
370 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
371
372
373 68/push 0x39/imm32
374
375 e8/call is-decimal-digit?/disp32
376
377 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
378
379
380 68/push "F - test-is-decimal-digit-at-9"/imm32
381 68/push 1/imm32/true
382 50/push-eax
383
384 e8/call check-ints-equal/disp32
385
386 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
387 c3/return
388
389 test-is-decimal-digit-above-9:
390
391
392 68/push 0x3a/imm32
393
394 e8/call is-decimal-digit?/disp32
395
396 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
397
398
399 68/push "F - test-is-decimal-digit-above-9"/imm32
400 68/push 0/imm32/false
401 50/push-eax
402
403 e8/call check-ints-equal/disp32
404
405 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
406 c3/return
407
408