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
14 0/imm32
15
16 0/imm32
17
18 8/imm32
19
20 00 00 00 00 00 00 00 00
21
22
23
24
25 == code
26
27
28
29
30
31 write-byte-buffered:
32
33 55/push-EBP
34 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
35
36 51/push-ECX
37 57/push-EDI
38
39 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
40
41 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 4/disp8 .
42
43 3b/compare 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 0xc/disp8 .
44 7c/jump-if-lesser $write-byte-buffered:to-stream/disp8
45
46
47 57/push-EDI
48
49 e8/call flush/disp32
50
51 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
52
53
54 8d/copy-address 1/mod/*+disp8 7/rm32/EDI . . . 0/r32/EAX 4/disp8 .
55 50/push-EAX
56
57 e8/call clear-stream/disp32
58
59 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
60
61 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . .
62 $write-byte-buffered:to-stream:
63
64
65 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
66 8a/copy-byte 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/AL 0xc/disp8 .
67 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX . 0/r32/AL 0x10/disp8 .
68
69 ff 0/subop/increment 1/mod/*+disp8 7/rm32/EDI . . . . 4/disp8 .
70 $write-byte-buffered:end:
71
72 5f/pop-to-EDI
73 59/pop-to-ECX
74
75 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
76 5d/pop-to-EBP
77 c3/return
78
79 flush:
80
81 55/push-EBP
82 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
83
84 50/push-EAX
85 51/push-ECX
86
87 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 .
88
89
90 8d/copy-address 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 .
91 51/push-ECX
92 ff 6/subop/push 0/mod/indirect 0/rm32/EAX . . . . . .
93
94 e8/call write-stream/disp32
95
96 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
97 $flush:end:
98
99 59/pop-to-ECX
100 58/pop-to-EAX
101
102 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
103 5d/pop-to-EBP
104 c3/return
105
106 test-write-byte-buffered-single:
107
108
109
110
111 68/push _test-stream/imm32
112
113 e8/call clear-stream/disp32
114
115 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
116
117
118 b8/copy-to-EAX _test-buffered-file/imm32
119 05/add-to-EAX 4/imm32
120 50/push-EAX
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 b8/copy-to-EAX _test-buffered-file/imm32
165 05/add-to-EAX 4/imm32
166 50/push-EAX
167
168 e8/call clear-stream/disp32
169
170 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
171
172
173
174 68/push "abcdef"/imm32
175 b8/copy-to-EAX _test-buffered-file/imm32
176 05/add-to-EAX 4/imm32
177 50/push-EAX
178
179 e8/call write/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
182
183
184 68/push 0x67/imm32
185 68/push _test-buffered-file/imm32
186
187 e8/call write-byte-buffered/disp32
188
189 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
190
191
192 68/push _test-buffered-file/imm32
193
194 e8/call flush/disp32
195
196 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
197
198
199 68/push "F - test-write-byte-buffered-multiple-flushes: 1"/imm32
200 68/push "abcdefg"/imm32
201 68/push _test-stream/imm32
202
203 e8/call check-stream-equal/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
206
207 c3/return
208
209
210
211
212 append-byte:
213
214 55/push-EBP
215 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
216
217 51/push-ECX
218 57/push-EDI
219
220 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 8/disp8 .
221
222 8b/copy 0/mod/indirect 7/rm32/EDI . . . 1/r32/ECX . .
223
224 3b/compare 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 8/disp8 .
225 7d/jump-if-greater-or-equal $append-byte:abort/disp8
226 $append-byte:to-stream:
227
228
229 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
230 8a/copy-byte 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/AL 0xc/disp8 .
231 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX . 0/r32/AL 0xc/disp8 .
232
233 ff 0/subop/increment 0/mod/indirect 7/rm32/EDI . . . . . .
234 $append-byte:end:
235
236 5f/pop-to-EDI
237 59/pop-to-ECX
238
239 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
240 5d/pop-to-EBP
241 c3/return
242
243 $append-byte:abort:
244
245
246 68/push "append-byte: out of space\n"/imm32
247 68/push 2/imm32/stderr
248
249 e8/call _write/disp32
250
251 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
252
253 bb/copy-to-EBX 1/imm32
254 b8/copy-to-EAX 1/imm32/exit
255 cd/syscall 0x80/imm8
256
257
258 test-append-byte-single:
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 0x41/imm32
271 68/push _test-stream/imm32
272
273 e8/call append-byte/disp32
274
275 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
276
277
278 68/push "F - test-append-byte-single"/imm32
279 68/push "A"/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