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