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