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