https://github.com/akkartik/mu/blob/master/subx/064write-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 "A"/imm32
153 68/push _test-stream/imm32
154
155 e8/call check-stream-equal/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
158
159 c3/return
160
161 test-write-byte-multiple-flushes:
162
163
164
165
166 68/push _test-stream/imm32
167
168 e8/call clear-stream/disp32
169
170 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
171
172
173 b8/copy-to-EAX _test-buffered-file/imm32
174 05/add-to-EAX 4/imm32
175 50/push-EAX
176
177 e8/call clear-stream/disp32
178
179 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
180
181
182
183 68/push "abcdef"/imm32
184 b8/copy-to-EAX _test-buffered-file/imm32
185 05/add-to-EAX 4/imm32
186 50/push-EAX
187
188 e8/call write/disp32
189
190 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
191
192
193 68/push 0x67/imm32
194 68/push _test-buffered-file/imm32
195
196 e8/call write-byte/disp32
197
198 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
199
200
201 68/push _test-buffered-file/imm32
202
203 e8/call flush/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
206
207
208 68/push "F - test-write-byte-multiple-flushes: 1"/imm32
209 68/push "abcdefg"/imm32
210 68/push _test-stream/imm32
211
212 e8/call check-stream-equal/disp32
213
214 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
215
216 c3/return
217
218