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