https://github.com/akkartik/mu/blob/master/078emit-hex.subx
1 == code
2
3
4
5
6
7 emit-hex:
8
9 55/push-ebp
10 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
11
12 50/push-eax
13 51/push-ecx
14 52/push-edx
15 53/push-ebx
16 57/push-edi
17
18 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
19
20 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 3/r32/ebx 0xc/disp8 .
21
22 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0x10/disp8 .
23
24 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . .
25 $emit-hex:loop:
26
27 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . .
28 7d/jump-if-greater-or-equal $emit-hex:end/disp8
29
30
31 53/push-ebx
32 57/push-edi
33
34 e8/call print-byte-buffered/disp32
35
36 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
37
38
39 68/push 0x20/imm32/space
40 57/push-edi
41
42 e8/call write-byte-buffered/disp32
43
44 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
45
46 c1/shift 5/subop/logic-right 3/mod/direct 3/rm32/ebx . . . . . 8/imm8
47 $emit-hex:continue:
48
49 41/increment-ecx
50 eb/jump $emit-hex:loop/disp8
51 $emit-hex:end:
52
53 5f/pop-to-edi
54 5b/pop-to-ebx
55 5a/pop-to-edx
56 59/pop-to-ecx
57 58/pop-to-eax
58
59 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
60 5d/pop-to-ebp
61 c3/return
62
63 test-emit-hex-single-byte:
64
65
66
67 68/push _test-output-stream/imm32
68
69 e8/call clear-stream/disp32
70
71 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
72
73
74 b8/copy-to-eax _test-output-buffered-file/imm32
75 05/add-to-eax 4/imm32
76 50/push-eax
77
78 e8/call clear-stream/disp32
79
80 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
81
82
83 68/push 1/imm32
84 68/push 0xab/imm32
85 68/push _test-output-buffered-file/imm32
86
87 e8/call emit-hex/disp32
88
89 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
90
91
92 68/push _test-output-buffered-file/imm32
93
94 e8/call flush/disp32
95
96 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
97
98
99 68/push "F - test-emit-hex-single-byte"/imm32
100 68/push 0x206261/imm32
101
102 b8/copy-to-eax _test-output-stream/imm32
103 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
104
105 e8/call check-ints-equal/disp32
106
107 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
108
109 c3/return
110
111 test-emit-hex-multiple-byte:
112
113
114
115 68/push _test-output-stream/imm32
116
117 e8/call clear-stream/disp32
118
119 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
120
121
122 b8/copy-to-eax _test-output-buffered-file/imm32
123 05/add-to-eax 4/imm32
124 50/push-eax
125
126 e8/call clear-stream/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
129
130
131 68/push 2/imm32
132 68/push 0x1234/imm32
133 68/push _test-output-buffered-file/imm32
134
135 e8/call emit-hex/disp32
136
137 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
138
139
140 68/push _test-output-buffered-file/imm32
141
142 e8/call flush/disp32
143
144 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
145
146
147 68/push "F - test-emit-hex-multiple-byte/1"/imm32
148 68/push "34 12 "/imm32
149 68/push _test-output-stream/imm32
150
151 e8/call check-stream-equal/disp32
152
153 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
154
155 c3/return
156
157 test-emit-hex-zero-pad:
158
159
160
161 68/push _test-output-stream/imm32
162
163 e8/call clear-stream/disp32
164
165 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
166
167
168 b8/copy-to-eax _test-output-buffered-file/imm32
169 05/add-to-eax 4/imm32
170 50/push-eax
171
172 e8/call clear-stream/disp32
173
174 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
175
176
177 68/push 2/imm32
178 68/push 0xab/imm32
179 68/push _test-output-buffered-file/imm32
180
181 e8/call emit-hex/disp32
182
183 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
184
185
186 68/push _test-output-buffered-file/imm32
187
188 e8/call flush/disp32
189
190 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
191
192
193 68/push "F - test-emit-hex-zero-pad/1"/imm32
194 68/push "ab 00 "/imm32
195 68/push _test-output-stream/imm32
196
197 e8/call check-stream-equal/disp32
198
199 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
200
201 c3/return
202
203 test-emit-hex-negative:
204
205
206
207 68/push _test-output-stream/imm32
208
209 e8/call clear-stream/disp32
210
211 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
212
213
214 b8/copy-to-eax _test-output-buffered-file/imm32
215 05/add-to-eax 4/imm32
216 50/push-eax
217
218 e8/call clear-stream/disp32
219
220 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
221
222
223 68/push 2/imm32
224 68/push -1/imm32
225 68/push _test-output-buffered-file/imm32
226
227 e8/call emit-hex/disp32
228
229 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
230
231
232 68/push _test-output-buffered-file/imm32
233
234 e8/call flush/disp32
235
236 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
237
238
239 68/push "F - test-emit-hex-negative/1"/imm32
240 68/push "ff ff "/imm32
241 68/push _test-output-stream/imm32
242
243 e8/call check-stream-equal/disp32
244
245 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
246
247 c3/return
248
249