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
100
101
102 test-read-byte-single:
103
104
105
106
107 68/push _test-stream/imm32
108
109 e8/call clear-stream/disp32
110
111 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
112
113
114 b8/copy-to-EAX _test-buffered-file/imm32
115 05/add-to-EAX 4/imm32
116 50/push-EAX
117
118 e8/call clear-stream/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
121
122
123 68/push "Ab"/imm32
124 68/push _test-stream/imm32
125
126 e8/call write/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
129
130
131 68/push _test-buffered-file/imm32
132
133 e8/call read-byte/disp32
134
135 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
136
137
138 68/push "F - test-read-byte-single"/imm32
139 68/push 0x41/imm32
140 50/push-EAX
141
142 e8/call check-ints-equal/disp32
143
144 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
145
146 c3/return
147
148 test-read-byte-multiple:
149
150
151
152
153 68/push _test-stream/imm32
154
155 e8/call clear-stream/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
158
159
160 b8/copy-to-EAX _test-buffered-file/imm32
161 05/add-to-EAX 4/imm32
162 50/push-EAX
163
164 e8/call clear-stream/disp32
165
166 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
167
168
169 68/push "Ab"/imm32
170 68/push _test-stream/imm32
171
172 e8/call write/disp32
173
174 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
175
176
177 68/push _test-buffered-file/imm32
178
179 e8/call read-byte/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
182
183
184 68/push _test-buffered-file/imm32
185
186 e8/call read-byte/disp32
187
188 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
189
190
191 68/push "F - test-read-byte-multiple"/imm32
192 68/push 0x62/imm32
193 50/push-EAX
194
195 e8/call check-ints-equal/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
198
199 c3/return
200
201 test-read-byte-end-of-file:
202
203
204
205
206 68/push _test-stream/imm32
207
208 e8/call clear-stream/disp32
209
210 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
211
212
213 b8/copy-to-EAX _test-buffered-file/imm32
214 05/add-to-EAX 4/imm32
215 50/push-EAX
216
217 e8/call clear-stream/disp32
218
219 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
220
221
222 68/push _test-buffered-file/imm32
223
224 e8/call read-byte/disp32
225
226 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
227
228
229 68/push "F - test-read-byte-end-of-file"/imm32
230 68/push -1/imm32
231 50/push-EAX
232
233 e8/call check-ints-equal/disp32
234
235 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
236
237 c3/return
238
239 == data
240
241 _test-buffered-file:
242
243 _test-stream/imm32
244
245 00 00 00 00
246
247 00 00 00 00
248
249 08 00 00 00
250
251 00 00 00 00 00 00 00 00
252
253