https://github.com/akkartik/mu/blob/master/subx/056write.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 == code
19
20
21
22
23
24 e8/call run-tests/disp32
25
26 8b/copy 0/mod/indirect 5/rm32/.disp32 3/r32/EBX Num-test-failures/disp32
27 b8/copy-to-EAX 1/imm32
28 cd/syscall 0x80/imm8
29
30
31 write:
32
33 55/push-EBP
34 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
35
36 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8 0x08000000/imm32
37 7d/jump-if-greater-or-equal $write:fake/disp8
38
39 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
40 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8
41
42 e8/call _write/disp32
43
44 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
45 eb/jump $write:end/disp8
46 $write:fake:
47
48
49 50/push-EAX
50 51/push-ECX
51 52/push-EDX
52 53/push-EBX
53
54 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 1/r32/ECX 8/disp8
55
56 8b/copy 0/mod/indirect 1/rm32/ECX 2/r32/EDX
57
58 8b/copy 1/mod/*+disp8 1/rm32/ECX 3/r32/EBX 8/disp8
59
60
61 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0xc/disp8
62
63 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 3/index/EBX 3/r32/EBX 0xc/disp8
64 53/push-EBX
65
66 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 2/index/EDX 3/r32/EBX 0xc/disp8
67 53/push-EBX
68
69 e8/call _append-3/disp32
70
71 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
72
73 01/add 0/mod/indirect 1/rm32/ECX 0/r32/EAX
74
75 5b/pop-to-EBX
76 5a/pop-to-EDX
77 59/pop-to-ECX
78 58/pop-to-EAX
79 $write:end:
80
81 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
82 5d/pop-to-EBP
83 c3/return
84
85 clear-stream:
86
87 55/push-EBP
88 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP
89
90 50/push-EAX
91 51/push-ECX
92
93 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 8/disp8
94
95 8b/copy 1/mod/*+disp8 0/rm32/EAX 1/r32/ECX 8/disp8
96
97 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX 1/r32/ECX 0xc/disp8
98
99 c7/copy 0/mod/direct 0/rm32/EAX 0/imm32
100
101 c7/copy 1/mod/*+disp8 0/rm32/EAX 4/disp8 0/imm32
102
103 81 0/subop/add 3/mod/direct 0/rm32/EAX 0xc/imm32
104
105 $clear-stream:loop:
106
107 39/compare 3/mod/direct 0/rm32/EAX 1/r32/ECX
108 7d/jump-if-greater-or-equal $clear-stream:end/disp8
109
110 c7/copy 0/mod/direct 0/rm32/EAX 0/imm32
111
112 81 0/subop/add 3/mod/direct 0/rm32/EAX 4/imm32
113 eb/jump $clear-stream:loop/disp8
114 $clear-stream:end:
115
116 59/pop-to-ECX
117 58/pop-to-EAX
118
119 89/copy 3/mod/direct 4/rm32/ESP 5/r32/EBP
120 5d/pop-to-EBP
121 c3/return
122
123 test-write-single:
124
125
126 68/push _test-stream/imm32
127
128 e8/call clear-stream/disp32
129
130 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
131
132
133 68/push "Ab"/imm32
134 68/push _test-stream/imm32
135
136 e8/call write/disp32
137
138 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
139
140
141 68/push "F - test-read-single: return EAX"/imm32
142 68/push 2/imm32
143 50/push-EAX
144
145 e8/call check-ints-equal/disp32
146
147 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
148
149
150 68/push "F - test-write-single"/imm32
151 68/push 0x006241/imm32/Ab
152
153 b8/copy-to-EAX _test-stream/imm32
154 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 0xc/disp8
155
156 e8/call check-ints-equal/disp32
157
158 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
159
160 c3/return
161
162 test-write-appends:
163
164
165 68/push _test-stream/imm32
166
167 e8/call clear-stream/disp32
168
169 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
170
171
172 68/push "C"/imm32
173 68/push _test-stream/imm32
174
175 e8/call write/disp32
176
177 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
178
179
180 68/push "D"/imm32
181 68/push _test-stream/imm32
182
183 e8/call write/disp32
184
185 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
186
187
188 68/push "F - test-write-appends"/imm32
189 68/push 0x00004443/imm32/C-D
190
191 b8/copy-to-EAX _test-stream/imm32
192 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 0xc/disp8
193
194 e8/call check-ints-equal/disp32
195
196 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
197
198 c3/return
199
200 == data
201
202 _test-stream:
203
204 00 00 00 00
205
206 00 00 00 00
207
208 08 00 00 00
209
210 00 00 00 00 00 00 00 00
211
212