https://github.com/akkartik/mu/blob/main/linux/117write-int-hex.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 write-byte-hex-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 $write-byte-hex-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-write-byte-hex-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 write-byte-hex-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-write-byte-hex-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 write-int32-hex:
179
180 55/push-ebp
181 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
182 $write-int32-hex:hex-prefix:
183
184
185 68/push "0x"/imm32
186 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
187
188 e8/call write/disp32
189
190 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
191 $write-int32-hex:rest:
192
193
194 68/push 0x20/imm32
195 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
196 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
197
198 e8/call write-int32-hex-bits/disp32
199
200 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
201 $write-int32-hex:end:
202
203 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
204 5d/pop-to-ebp
205 c3/return
206
207
208
209 write-int32-hex-bits:
210
211
212
213
214
215
216
217
218
219
220 55/push-ebp
221 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
222
223 50/push-eax
224 51/push-ecx
225
226 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 .
227 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
228 $write-int32-hex-bits:loop:
229
230 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
231 7c/jump-if-< $write-int32-hex-bits:end/disp8
232
233 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
234 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
235
236 25/and-eax 0xf/imm32
237 e8/call to-hex-char/disp32
238
239
240 50/push-eax
241 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
242
243 e8/call append-byte/disp32
244
245 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
246
247 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
248 eb/jump $write-int32-hex-bits:loop/disp8
249 $write-int32-hex-bits:end:
250
251 59/pop-to-ecx
252 58/pop-to-eax
253
254 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
255 5d/pop-to-ebp
256 c3/return
257
258 test-write-int32-hex:
259
260
261
262
263 68/push _test-stream/imm32
264
265 e8/call clear-stream/disp32
266
267 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
268
269
270 68/push 0x8899aa/imm32
271 68/push _test-stream/imm32
272
273 e8/call write-int32-hex/disp32
274
275 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
276
277
278 68/push "F - test-write-int32-hex"/imm32
279 68/push "0x008899aa"/imm32
280 68/push _test-stream/imm32
281
282 e8/call check-stream-equal/disp32
283
284 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
285
286 c3/return
287
288 write-int32-hex-buffered:
289
290 55/push-ebp
291 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
292 $write-int32-hex-buffered:hex-prefix:
293
294
295 68/push "0x"/imm32
296 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
297
298 e8/call write-buffered/disp32
299
300 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
301 $write-int32-hex-buffered:rest:
302
303
304 68/push 0x20/imm32
305 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
306 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
307
308 e8/call write-int32-hex-bits-buffered/disp32
309
310 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
311 $write-int32-hex-buffered:end:
312
313 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
314 5d/pop-to-ebp
315 c3/return
316
317
318
319 write-int32-hex-bits-buffered:
320
321
322
323
324
325
326
327
328
329
330 55/push-ebp
331 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
332
333 50/push-eax
334 51/push-ecx
335
336 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 .
337 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
338 $write-int32-hex-bits-buffered:loop:
339
340 81 7/subop/compare 3/mod/direct 1/rm32/ecx . . . . . 0/imm32
341 7c/jump-if-< $write-int32-hex-bits-buffered:end/disp8
342
343 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
344 d3/>>ecx 5/subop/pad-zeroes 3/mod/direct 0/rm32/eax . . . . . .
345
346 25/and-eax 0xf/imm32
347 e8/call to-hex-char/disp32
348
349
350 50/push-eax
351 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
352
353 e8/call write-byte-buffered/disp32
354
355 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
356
357 81 5/subop/subtract 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
358 eb/jump $write-int32-hex-bits-buffered:loop/disp8
359 $write-int32-hex-bits-buffered:end:
360
361 59/pop-to-ecx
362 58/pop-to-eax
363
364 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
365 5d/pop-to-ebp
366 c3/return
367
368 test-write-int32-hex-buffered:
369
370
371
372
373 68/push _test-stream/imm32
374
375 e8/call clear-stream/disp32
376
377 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
378
379
380 68/push $_test-buffered-file->buffer/imm32
381
382 e8/call clear-stream/disp32
383
384 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
385
386
387 68/push 0x8899aa/imm32
388 68/push _test-buffered-file/imm32
389
390 e8/call write-int32-hex-buffered/disp32
391
392 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
393
394
395 68/push _test-buffered-file/imm32
396
397 e8/call flush/disp32
398
399 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
400 +-- 18 lines: #? # dump line --------------------------------------------------------------------------------------------------------------------------------------------------------
418
419
420 68/push "F - test-write-int32-hex-buffered"/imm32
421 68/push "0x008899aa"/imm32
422 68/push _test-stream/imm32
423
424 e8/call check-stream-equal/disp32
425
426 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
427
428 c3/return
429
430