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