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 68/push _test-buffered-file->buffer/imm32
146
147 e8/call clear-stream/disp32
148
149 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
150
151
152 68/push 0xa/imm32
153 68/push _test-buffered-file/imm32
154
155 e8/call print-byte-buffered/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
158
159
160 68/push _test-buffered-file/imm32
161
162 e8/call flush/disp32
163
164 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
165
166
167 68/push "F - test-print-byte-buffered"/imm32
168 68/push "0a"/imm32
169 68/push _test-stream/imm32
170
171 e8/call check-stream-equal/disp32
172
173 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
174
175 c3/return
176
177 print-int32:
178
179
180
181
182
183
184
185
186
187
188
189 55/push-ebp
190 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
191
192 50/push-eax
193 51/push-ecx
194
195 b9/copy-to-ecx 0x1c/imm32
196 $print-int32:print-hex-prefix:
197
198
199 68/push "0x"/imm32
200 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
201
202 e8/call write/disp32
203
204 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
205 $print-int32:loop:
206
207 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
208 7c/jump-if-lesser $print-int32:end/disp8
209
210 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
211 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
212
213 25/and-eax 0xf/imm32
214 e8/call to-hex-char/disp32
215
216
217 50/push-eax
218 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
219
220 e8/call append-byte/disp32
221
222 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
223
224 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
225 eb/jump $print-int32:loop/disp8
226 $print-int32:end:
227
228 59/pop-to-ecx
229 58/pop-to-eax
230
231 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
232 5d/pop-to-ebp
233 c3/return
234
235 test-print-int32:
236
237
238
239
240 68/push _test-stream/imm32
241
242 e8/call clear-stream/disp32
243
244 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
245
246
247 68/push 0x8899aa/imm32
248 68/push _test-stream/imm32
249
250 e8/call print-int32/disp32
251
252 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
253
254
255 68/push "F - test-print-int32"/imm32
256 68/push "0x008899aa"/imm32
257 68/push _test-stream/imm32
258
259 e8/call check-stream-equal/disp32
260
261 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
262
263 c3/return
264
265 print-int32-buffered:
266
267
268
269
270
271
272
273
274
275
276
277 55/push-ebp
278 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
279
280 50/push-eax
281 51/push-ecx
282
283 b9/copy-to-ecx 0x1c/imm32
284 $print-int32-buffered:print-hex-prefix:
285
286
287 68/push "0x"/imm32
288 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
289
290 e8/call write-buffered/disp32
291
292 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
293 $print-int32-buffered:loop:
294
295 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
296 7c/jump-if-lesser $print-int32-buffered:end/disp8
297
298 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
299 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
300
301 25/and-eax 0xf/imm32
302 e8/call to-hex-char/disp32
303
304
305 50/push-eax
306 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
307
308 e8/call write-byte-buffered/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
311
312 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
313 eb/jump $print-int32-buffered:loop/disp8
314 $print-int32-buffered:end:
315
316 59/pop-to-ecx
317 58/pop-to-eax
318
319 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
320 5d/pop-to-ebp
321 c3/return
322
323 test-print-int32-buffered:
324
325
326
327
328 68/push _test-stream/imm32
329
330 e8/call clear-stream/disp32
331
332 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
333
334
335 68/push _test-buffered-file->buffer/imm32
336
337 e8/call clear-stream/disp32
338
339 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
340
341
342 68/push 0x8899aa/imm32
343 68/push _test-buffered-file/imm32
344
345 e8/call print-int32-buffered/disp32
346
347 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
348
349
350 68/push _test-buffered-file/imm32
351
352 e8/call flush/disp32
353
354 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
355 +-- 18 lines: #? # dump line -----------------------------------------------------------------------------------------------------------------------------
373
374
375 68/push "F - test-print-int32-buffered"/imm32
376 68/push "0x008899aa"/imm32
377 68/push _test-stream/imm32
378
379 e8/call check-stream-equal/disp32
380
381 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
382
383 c3/return
384
385