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