https://github.com/akkartik/mu/blob/master/subx/065write-buffered.subx
1
2
3 == code
4
5
6
7
8 write-buffered:
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 55/push-EBP
31 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
32
33 50/push-EAX
34 51/push-ECX
35 52/push-EDX
36 53/push-EBX
37 56/push-ESI
38 57/push-EDI
39
40 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 0/r32/EAX 0xc/disp8 .
41
42 8d/copy-address 1/mod/*+disp8 0/rm32/EAX . . . 6/r32/ESI 4/disp8 .
43
44 8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
45 8d/copy-address 0/mod/indirect 4/rm32/sib 6/base/ESI 1/index/ECX . 1/r32/ECX . .
46
47 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 7/r32/EDI 8/disp8 .
48
49 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 2/r32/EDX 0xc/disp8 .
50
51 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 .
52 $write-buffered:loop:
53
54 39/compare 3/mod/direct 6/rm32/ESI . . . 1/r32/ECX . .
55 73/jump-if-greater-or-equal-unsigned $write-buffered:loop-end/disp8
56
57 39/compare 3/mod/direct 3/rm32/EBX . . . 2/r32/EDX . .
58 7c/jump-if-lesser $write-buffered:to-stream/disp8
59
60 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 .
61
62
63 57/push-EDI
64
65 e8/call flush/disp32
66
67 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
68
69
70 8d/copy-address 1/mod/*+disp8 7/rm32/EDI . . . 0/r32/EAX 4/disp8 .
71 50/push-EAX
72
73 e8/call clear-stream/disp32
74
75 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
76
77 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . .
78 $write-buffered:to-stream:
79
80
81
82 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . .
83 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . .
84
85 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/EDI 3/index/EBX . 0/r32/AL 0x10/disp8 .
86
87 43/increment-EBX
88
89 46/increment-ESI
90 eb/jump $write-buffered:loop/disp8
91 $write-buffered:loop-end:
92
93 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 .
94 $write-buffered:end:
95
96 5f/pop-to-EDI
97 5e/pop-to-ESI
98 5b/pop-to-EBX
99 5a/pop-to-EDX
100 59/pop-to-ECX
101 58/pop-to-EAX
102
103 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
104 5d/pop-to-EBP
105 c3/return
106
107 test-write-buffered:
108
109
110
111
112 68/push _test-stream/imm32
113
114 e8/call clear-stream/disp32
115
116 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
117
118
119 b8/copy-to-EAX _test-buffered-file/imm32
120 05/add-to-EAX 4/imm32
121 50/push-EAX
122
123 e8/call clear-stream/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
126
127
128 68/push "Abc"/imm32
129 68/push _test-buffered-file/imm32
130
131 e8/call write-buffered/disp32
132
133 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
134
135
136 68/push _test-buffered-file/imm32
137
138 e8/call flush/disp32
139
140 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
141
142
143 68/push "F - test-write-buffered-single"/imm32
144 68/push "Abc"/imm32
145 68/push _test-stream/imm32
146
147 e8/call check-stream-equal/disp32
148
149 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
150
151 c3/return
152
153 test-write-buffered-with-intermediate-flush:
154
155
156
157
158 68/push _test-stream/imm32
159
160 e8/call clear-stream/disp32
161
162 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
163
164
165 b8/copy-to-EAX _test-buffered-file/imm32
166 05/add-to-EAX 4/imm32
167 50/push-EAX
168
169 e8/call clear-stream/disp32
170
171 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
172
173
174
175
176 68/push "Abcdefg"/imm32
177 68/push _test-buffered-file/imm32
178
179 e8/call write-buffered/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
182
183
184
185
186 68/push "F - test-write-buffered-with-intermediate-flush: flushed data"/imm32
187 68/push 6/imm32
188
189 b8/copy-to-EAX _test-stream/imm32
190 ff 6/subop/push 0/mod/indirect 0/rm32/EAX . . . . . .
191
192 e8/call check-ints-equal/disp32
193
194 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
195
196
197
198 68/push "F - test-write-buffered-with-intermediate-flush: unflushed bytes"/imm32
199 68/push 1/imm32
200
201 b8/copy-to-EAX _test-buffered-file/imm32
202 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 4/disp8 .
203
204 e8/call check-ints-equal/disp32
205
206 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
207
208 c3/return
209
210 == data
211
212
213 Stderr:
214
215 2/imm32
216
217 0/imm32
218
219 0/imm32
220
221 8/imm32
222
223 00 00 00 00 00 00 00 00
224
225
226
227
228