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