https://github.com/akkartik/mu/blob/main/108write.subx
1
2
3
4
5
6 == code
7
8
9
10
11 write:
12
13 55/push-ebp
14 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
15
16 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 0/imm32
17 74/jump-if-= $write:end/disp8
18
19 50/push-eax
20 51/push-ecx
21 52/push-edx
22 53/push-ebx
23
24 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 8/disp8 .
25
26 8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . .
27
28 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 3/r32/ebx 8/disp8 .
29
30
31 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
32
33 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ecx 3/index/ebx . 3/r32/ebx 0xc/disp8 .
34 53/push-ebx
35
36 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ecx 2/index/edx . 3/r32/ebx 0xc/disp8 .
37 53/push-ebx
38
39 e8/call _append-3/disp32
40
41 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
42
43 01/add 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
44
45 5b/pop-to-ebx
46 5a/pop-to-edx
47 59/pop-to-ecx
48 58/pop-to-eax
49 $write:end:
50
51 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
52 5d/pop-to-ebp
53 c3/return
54
55 test-write-single:
56
57
58 68/push _test-stream/imm32
59
60 e8/call clear-stream/disp32
61
62 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
63
64
65 68/push "Ab"/imm32
66 68/push _test-stream/imm32
67
68 e8/call write/disp32
69
70 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
71
72
73 68/push "F - test-write-single"/imm32
74 68/push 0x006241/imm32/Ab
75
76 b8/copy-to-eax _test-stream/imm32
77 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
78
79 e8/call check-ints-equal/disp32
80
81 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
82
83 c3/return
84
85 test-write-appends:
86
87
88 68/push _test-stream/imm32
89
90 e8/call clear-stream/disp32
91
92 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
93
94
95 68/push "C"/imm32
96 68/push _test-stream/imm32
97
98 e8/call write/disp32
99
100 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
101
102
103 68/push "D"/imm32
104 68/push _test-stream/imm32
105
106 e8/call write/disp32
107
108 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
109
110
111 68/push "F - test-write-appends"/imm32
112 68/push 0x00004443/imm32/C-D
113
114 b8/copy-to-eax _test-stream/imm32
115 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
116
117 e8/call check-ints-equal/disp32
118
119 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
120
121 c3/return
122
123 == data
124
125 _test-stream:
126
127 0/imm32
128
129 0/imm32
130
131 0x10/imm32
132
133 00 00 00 00 00 00 00 00
134 00 00 00 00 00 00 00 00
135
136 == code
137
138 try-write:
139
140 55/push-ebp
141 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
142
143 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 0/imm32
144 74/jump-if-= $try-write:end/disp8
145
146 51/push-ecx
147
148
149 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 8/disp8 .
150 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 8/disp8 .
151 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
152 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 0xc/disp8 .
153 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
154
155 3d/compare-eax-and 0/imm32
156 7c/jump-if-< $try-write:end/disp8
157
158
159 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
160 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
161
162 e8/call write/disp32
163
164 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
165
166 59/pop-to-ecx
167
168 b8/copy-to-eax 0/imm32
169 $try-write:end:
170
171 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
172 5d/pop-to-ebp
173 c3/return
174
175
176 space-remaining-in-stream:
177
178 55/push-ebp
179 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
180
181 51/push-ecx
182
183 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 8/disp8 .
184 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 8/disp8 .
185 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
186
187 59/pop-to-ecx
188 $space-remaining-in-stream:end:
189
190 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
191 5d/pop-to-ebp
192 c3/return
193
194 stream-size:
195
196 55/push-ebp
197 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
198
199 51/push-ecx
200
201 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 8/disp8 .
202 8b/copy 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
203
204 59/pop-to-ecx
205 $stream-size:end:
206
207 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
208 5d/pop-to-ebp
209 c3/return
210
211
212 _append-3:
213
214 55/push-ebp
215 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
216
217 51/push-ecx
218
219
220 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 0/r32/eax 0xc/disp8 .
221 2b/subtract 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 8/disp8 .
222 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 1/r32/ecx 0x10/disp8 .
223 2b/subtract 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
224
225 3d/compare-eax-and 0/imm32
226 7c/jump-if-< $_append-3:abort/disp8
227
228
229 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 0/r32/eax 0x10/disp8 .
230 8b/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
231 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 1/index/ecx . 1/r32/ecx 4/disp8 .
232 51/push-ecx
233
234 8d/copy-address 1/mod/*+disp8 0/rm32/eax . . . 1/r32/ecx 4/disp8 .
235 51/push-ecx
236
237 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
238
239 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
240
241 e8/call _append-4/disp32
242
243 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
244 $_append-3:end:
245
246 59/pop-to-ecx
247
248 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
249 5d/pop-to-ebp
250 c3/return
251
252 $_append-3:abort:
253 (abort "_append-3 about to overflow")
254
255
256
257 _append-4:
258
259 55/push-ebp
260 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
261
262 51/push-ecx
263 52/push-edx
264 53/push-ebx
265 56/push-esi
266 57/push-edi
267
268 b8/copy-to-eax 0/imm32
269
270 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
271
272 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 .
273
274 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0x10/disp8 .
275
276 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x14/disp8 .
277 $_append-4:loop:
278
279 39/compare 3/mod/direct 6/rm32/esi . . . 1/r32/ecx . .
280 73/jump-if-addr>= $_append-4:end/disp8
281
282 39/compare 3/mod/direct 7/rm32/edi . . . 2/r32/edx . .
283 0f 83/jump-if-addr>= $_append-4:abort/disp32
284
285 8a/copy-byte 0/mod/indirect 6/rm32/esi . . . 3/r32/BL . .
286 88/copy-byte 0/mod/indirect 7/rm32/edi . . . 3/r32/BL . .
287
288 40/increment-eax
289
290 46/increment-esi
291
292 47/increment-edi
293 eb/jump $_append-4:loop/disp8
294 $_append-4:end:
295
296 5f/pop-to-edi
297 5e/pop-to-esi
298 5b/pop-to-ebx
299 5a/pop-to-edx
300 59/pop-to-ecx
301
302 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
303 5d/pop-to-ebp
304 c3/return
305
306 $_append-4:abort:
307 (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "_append-4: stream full at " 3 0)
308 (draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0 %eax 3 0)
309 (abort "")
310
311
312