https://github.com/akkartik/mu/blob/main/113write-stream.subx
1
2
3 == code
4
5
6
7
8
9
10
11
12
13
14
15
16
17 write-stream:
18
19 55/push-ebp
20 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
21
22 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x08000000/imm32
23 73/jump-if-addr>= $write-stream:fake/disp8
24
25 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
26 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
27
28 e8/call _write-stream/disp32
29
30 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
31 eb/jump $write-stream:end/disp8
32 $write-stream:fake:
33
34
35 50/push-eax
36 56/push-esi
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 5/rm32/ebp . . 6/r32/esi 0xc/disp8 .
42
43
44 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . .
45 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 .
46 50/push-eax
47
48 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
49 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 .
50 50/push-eax
51
52 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 8/disp8 .
53 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 .
54 50/push-eax
55
56 8b/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
57 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 .
58 50/push-eax
59
60 e8/call _append-4/disp32
61
62 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32
63
64 01/add 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . .
65
66 01/add 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
67
68 5f/pop-to-edi
69 5e/pop-to-esi
70 58/pop-to-eax
71 $write-stream:end:
72
73 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
74 5d/pop-to-ebp
75 c3/return
76
77 _write-stream:
78
79 55/push-ebp
80 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
81
82 50/push-eax
83 51/push-ecx
84 52/push-edx
85 53/push-ebx
86 56/push-esi
87 57/push-edi
88
89 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 0xc/disp8 .
90
91 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 7/r32/edi 4/disp8 .
92
93 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . .
94
95
96 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 3/r32/ebx 8/disp8 .
97
98 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 7/index/edi . 1/r32/ecx 0xc/disp8 .
99
100 29/subtract 3/mod/direct 2/rm32/edx . . . 7/r32/edi . .
101
102 e8/call syscall_write/disp32
103
104 3d/compare-eax-with 0/imm32
105 0f 8c/jump-if-< $_write-stream:abort/disp32
106
107 01/add 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
108
109 5f/pop-to-edi
110 5e/pop-to-esi
111 5b/pop-to-ebx
112 5a/pop-to-edx
113 59/pop-to-ecx
114 58/pop-to-eax
115
116 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
117 5d/pop-to-ebp
118 c3/return
119
120 $_write-stream:abort:
121
122
123 68/push "_write-stream: failed to write to file\n"/imm32
124 68/push 2/imm32/stderr
125
126 e8/call _write/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
129
130 bb/copy-to-ebx 1/imm32
131 e8/call syscall_exit/disp32
132
133
134 test-write-stream-single:
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-stream2/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 "Ab"/imm32
153 68/push _test-stream2/imm32
154
155 e8/call write/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
158
159
160 68/push _test-stream2/imm32
161 68/push _test-stream/imm32
162
163 e8/call write-stream/disp32
164
165 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
166
167
168 68/push "F - test-write-stream-single"/imm32
169 68/push "Ab"/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 test-write-stream-appends:
179
180
181
182 68/push _test-stream/imm32
183
184 e8/call clear-stream/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
187
188
189 68/push _test-stream2/imm32
190
191 e8/call clear-stream/disp32
192
193 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
194
195
196 68/push "C"/imm32
197 68/push _test-stream2/imm32
198
199 e8/call write/disp32
200
201 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
202
203
204
205 68/push _test-stream2/imm32
206 68/push _test-stream/imm32
207
208 e8/call write-stream/disp32
209
210 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
211
212
213
214 68/push "D"/imm32
215 68/push _test-stream2/imm32
216
217 e8/call write/disp32
218
219 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
220
221
222 68/push _test-stream2/imm32
223 68/push _test-stream/imm32
224
225 e8/call write-stream/disp32
226
227 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
228
229
230 68/push "F - test-write-stream-appends"/imm32
231 68/push "CD"/imm32
232 68/push _test-stream/imm32
233
234 e8/call check-stream-equal/disp32
235
236 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
237
238 c3/return
239
240 == data
241
242 _test-stream2:
243
244 4/imm32
245
246 1/imm32
247
248 8/imm32
249
250 41/A 42/B 43/C 44/D 00 00 00 00
251
252