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-write-single"/imm32
142 68/push 0x006241/imm32/Ab
143
144 b8/copy-to-EAX _test-stream/imm32
145 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 0xc/disp8
146
147 e8/call check-ints-equal/disp32
148
149 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
150
151 c3/return
152
153 test-write-appends:
154
155
156 68/push _test-stream/imm32
157
158 e8/call clear-stream/disp32
159
160 81 0/subop/add 3/mod/direct 4/rm32/ESP 4/imm32
161
162
163 68/push "C"/imm32
164 68/push _test-stream/imm32
165
166 e8/call write/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
169
170
171 68/push "D"/imm32
172 68/push _test-stream/imm32
173
174 e8/call write/disp32
175
176 81 0/subop/add 3/mod/direct 4/rm32/ESP 8/imm32
177
178
179 68/push "F - test-write-appends"/imm32
180 68/push 0x00004443/imm32/C-D
181
182 b8/copy-to-EAX _test-stream/imm32
183 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX 0xc/disp8
184
185 e8/call check-ints-equal/disp32
186
187 81 0/subop/add 3/mod/direct 4/rm32/ESP 0xc/imm32
188
189 c3/return
190
191 == data
192
193 _test-stream:
194
195 00 00 00 00
196
197 00 00 00 00
198
199 08 00 00 00
200
201 00 00 00 00 00 00 00 00
202
203