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