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