https://github.com/akkartik/mu/blob/master/066print-int.subx
1
2
3 == code
4
5
6
7
8
9 to-hex-char:
10
11
12 3d/compare-eax-with 0x9/imm32/9
13 7f/jump-if-> $to-hex-char:else/disp8
14 05/add-to-eax 0x30/imm32/0
15 c3/return
16 $to-hex-char:else:
17
18 05/add-to-eax 0x57/imm32/a-10
19 c3/return
20
21 append-byte-hex:
22
23 55/push-ebp
24 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
25
26 50/push-eax
27
28 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
29 c1/shift 5/subop/logic-right 3/mod/direct 0/rm32/eax . . . . . 4/imm8
30 25/and-eax 0xf/imm32
31
32 e8/call to-hex-char/disp32
33
34
35 50/push-eax
36 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
37
38 e8/call append-byte/disp32
39
40 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
41
42 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
43 25/and-eax 0xf/imm32
44
45 e8/call to-hex-char/disp32
46
47
48 50/push-eax
49 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
50
51 e8/call append-byte/disp32
52
53 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
54 $append-byte-hex:end:
55
56 58/pop-to-eax
57
58 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
59 5d/pop-to-ebp
60 c3/return
61
62 test-append-byte-hex:
63
64
65
66
67 68/push _test-stream/imm32
68
69 e8/call clear-stream/disp32
70
71 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
72
73
74 68/push 0xa/imm32
75 68/push _test-stream/imm32
76
77 e8/call append-byte-hex/disp32
78
79 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
80
81
82 68/push "F - test-append-byte-hex"/imm32
83 68/push "0a"/imm32
84 68/push _test-stream/imm32
85
86 e8/call check-stream-equal/disp32
87
88 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
89
90 c3/return
91
92
93 print-byte-buffered:
94
95 55/push-ebp
96 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
97
98 50/push-eax
99
100 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
101 c1/shift 5/subop/logic-right 3/mod/direct 0/rm32/eax . . . . . 4/imm8
102 25/and-eax 0xf/imm32
103
104 e8/call to-hex-char/disp32
105
106
107 50/push-eax
108 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
109
110 e8/call write-byte-buffered/disp32
111
112 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
113
114 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
115 25/and-eax 0xf/imm32
116
117 e8/call to-hex-char/disp32
118
119
120 50/push-eax
121 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
122
123 e8/call write-byte-buffered/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
126 $print-byte-buffered:end:
127
128 58/pop-to-eax
129
130 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
131 5d/pop-to-ebp
132 c3/return
133
134 test-print-byte-buffered:
135
136
137
138
139 68/push _test-stream/imm32
140
141 e8/call clear-stream/disp32
142
143 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
144
145
146 68/push $_test-buffered-file->buffer/imm32
147
148 e8/call clear-stream/disp32
149
150 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
151
152
153 68/push 0xa/imm32
154 68/push _test-buffered-file/imm32
155
156 e8/call print-byte-buffered/disp32
157
158 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
159
160
161 68/push _test-buffered-file/imm32
162
163 e8/call flush/disp32
164
165 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
166
167
168 68/push "F - test-print-byte-buffered"/imm32
169 68/push "0a"/imm32
170 68/push _test-stream/imm32
171
172 e8/call check-stream-equal/disp32
173
174 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
175
176 c3/return
177
178 print-int32:
179
180
181
182
183
184
185
186
187
188
189
190 55/push-ebp
191 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
192
193 50/push-eax
194 51/push-ecx
195
196 b9/copy-to-ecx 0x1c/imm32
197 $print-int32:print-hex-prefix:
198
199
200 68/push "0x"/imm32
201 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
202
203 e8/call write/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
206 $print-int32:loop:
207
208 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
209 7c/jump-if-< $print-int32:end/disp8
210
211 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
212 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
213
214 25/and-eax 0xf/imm32
215 e8/call to-hex-char/disp32
216
217
218 50/push-eax
219 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
220
221 e8/call append-byte/disp32
222
223 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
224
225 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
226 eb/jump $print-int32:loop/disp8
227 $print-int32:end:
228
229 59/pop-to-ecx
230 58/pop-to-eax
231
232 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
233 5d/pop-to-ebp
234 c3/return
235
236 test-print-int32:
237
238
239
240
241 68/push _test-stream/imm32
242
243 e8/call clear-stream/disp32
244
245 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
246
247
248 68/push 0x8899aa/imm32
249 68/push _test-stream/imm32
250
251 e8/call print-int32/disp32
252
253 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
254
255
256 68/push "F - test-print-int32"/imm32
257 68/push "0x008899aa"/imm32
258 68/push _test-stream/imm32
259
260 e8/call check-stream-equal/disp32
261
262 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
263
264 c3/return
265
266 print-int32-buffered:
267
268
269
270
271
272
273
274
275
276
277
278 55/push-ebp
279 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
280
281 50/push-eax
282 51/push-ecx
283
284 b9/copy-to-ecx 0x1c/imm32
285 $print-int32-buffered:print-hex-prefix:
286
287
288 68/push "0x"/imm32
289 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
290
291 e8/call write-buffered/disp32
292
293 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
294 $print-int32-buffered:loop:
295
296 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
297 7c/jump-if-< $print-int32-buffered:end/disp8
298
299 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
300 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
301
302 25/and-eax 0xf/imm32
303 e8/call to-hex-char/disp32
304
305
306 50/push-eax
307 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
308
309 e8/call write-byte-buffered/disp32
310
311 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
312
313 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
314 eb/jump $print-int32-buffered:loop/disp8
315 $print-int32-buffered:end:
316
317 59/pop-to-ecx
318 58/pop-to-eax
319
320 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
321 5d/pop-to-ebp
322 c3/return
323
324 test-print-int32-buffered:
325
326
327
328
329 68/push _test-stream/imm32
330
331 e8/call clear-stream/disp32
332
333 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
334
335
336 68/push $_test-buffered-file->buffer/imm32
337
338 e8/call clear-stream/disp32
339
340 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
341
342
343 68/push 0x8899aa/imm32
344 68/push _test-buffered-file/imm32
345
346 e8/call print-int32-buffered/disp32
347
348 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
349
350
351 68/push _test-buffered-file/imm32
352
353 e8/call flush/disp32
354
355 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
356 +-- 18 lines: #? # dump line --------------------------------------------------------------------------------------------------------------------------------------------------------
374
375
376 68/push "F - test-print-int32-buffered"/imm32
377 68/push "0x008899aa"/imm32
378 68/push _test-stream/imm32
379
380 e8/call check-stream-equal/disp32
381
382 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
383
384 c3/return
385
386