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 Stdin:
15
16 00 00 00 00
17
18 00 00 00 00
19
20 00 00 00 00
21
22 08 00 00 00
23
24 00 00 00 00 00 00 00 00
25
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 8d/copy-address 1/mod/*+disp8 6/rm32/ESI 0/r32/EAX 4/disp8
61 50/push-EAX
62
63 e8/call clear-stream/disp32
64
65 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
66
67
68 50/push-EAX
69 ff 6/subop/push 0/mod/indirect 6/rm32/ESI
70
71 e8/call read/disp32
72
73 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
74
75 81 7/subop/compare 3/mod/direct 0/rm32/EAX 0/imm32
76 75/jump-if-not-equal $read-byte:from-stream/disp8
77 b8/copy-to-EAX 0xffffffff/imm32
78 eb/jump $read-byte:end/disp8
79 $read-byte:from-stream:
80
81
82 31/xor 3/mod/direct 0/rm32/EAX 0/r32/EAX
83 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX 0/r32/AL 0x10/disp8
84
85 ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI 8/disp8
86 $read-byte:end:
87
88 5e/pop-to-ESI
89 59/pop-to-ECX
90
91 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
92 5d/pop-to-EBP
93 c3/return
94
95
96
97 test-read-byte-single:
98
99
100
101
102 68/push _test-stream/imm32
103
104 e8/call clear-stream/disp32
105
106 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
107
108
109 b8/copy-to-EAX _test-buffered-file/imm32
110 05/add-to-EAX 4/imm32
111 50/push-EAX
112
113 e8/call clear-stream/disp32
114
115 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
116
117
118 68/push "Ab"/imm32
119 68/push _test-stream/imm32
120
121 e8/call write/disp32
122
123 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
124
125
126 68/push _test-buffered-file/imm32
127
128 e8/call read-byte/disp32
129
130 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
131
132
133 68/push "F - test-read-byte-single"/imm32
134 68/push 0x41/imm32
135 50/push-EAX
136
137 e8/call check-ints-equal/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
140
141 c3/return
142
143 test-read-byte-multiple:
144
145
146
147
148 68/push _test-stream/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 b8/copy-to-EAX _test-buffered-file/imm32
156 05/add-to-EAX 4/imm32
157 50/push-EAX
158
159 e8/call clear-stream/disp32
160
161 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
162
163
164 68/push "Ab"/imm32
165 68/push _test-stream/imm32
166
167 e8/call write/disp32
168
169 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
170
171
172 68/push _test-buffered-file/imm32
173
174 e8/call read-byte/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
177
178
179 68/push _test-buffered-file/imm32
180
181 e8/call read-byte/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
184
185
186 68/push "F - test-read-byte-multiple"/imm32
187 68/push 0x62/imm32
188 50/push-EAX
189
190 e8/call check-ints-equal/disp32
191
192 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
193
194 c3/return
195
196 test-read-byte-end-of-file:
197
198
199
200
201 68/push _test-stream/imm32
202
203 e8/call clear-stream/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
206
207
208 b8/copy-to-EAX _test-buffered-file/imm32
209 05/add-to-EAX 4/imm32
210 50/push-EAX
211
212 e8/call clear-stream/disp32
213
214 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
215
216
217 68/push _test-buffered-file/imm32
218
219 e8/call read-byte/disp32
220
221 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
222
223
224 68/push "F - test-read-byte-end-of-file"/imm32
225 68/push 0xffffffff/imm32
226 50/push-EAX
227
228 e8/call check-ints-equal/disp32
229
230 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
231
232 c3/return
233
234 == data
235
236
237 _test-buffered-file:
238
239 _test-stream/imm32
240
241 00 00 00 00
242
243 00 00 00 00
244
245 06 00 00 00
246
247 00 00 00 00 00 00
248
249