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 68/push _test-output-buffered-file->buffer/imm32
75
76 e8/call clear-stream/disp32
77
78 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
79
80
81 68/push 1/imm32
82 68/push 0xab/imm32
83 68/push _test-output-buffered-file/imm32
84
85 e8/call emit-hex/disp32
86
87 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
88
89
90 68/push _test-output-buffered-file/imm32
91
92 e8/call flush/disp32
93
94 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
95
96
97 68/push "F - test-emit-hex-single-byte"/imm32
98 68/push 0x206261/imm32
99
100 b8/copy-to-eax _test-output-stream/imm32
101 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . 0xc/disp8 .
102
103 e8/call check-ints-equal/disp32
104
105 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
106
107 c3/return
108
109 test-emit-hex-multiple-byte:
110
111
112
113 68/push _test-output-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 68/push _test-output-buffered-file->buffer/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 68/push 2/imm32
128 68/push 0x1234/imm32
129 68/push _test-output-buffered-file/imm32
130
131 e8/call emit-hex/disp32
132
133 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
134
135
136 68/push _test-output-buffered-file/imm32
137
138 e8/call flush/disp32
139
140 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
141
142
143 68/push "F - test-emit-hex-multiple-byte/1"/imm32
144 68/push "34 12 "/imm32
145 68/push _test-output-stream/imm32
146
147 e8/call check-stream-equal/disp32
148
149 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
150
151 c3/return
152
153 test-emit-hex-zero-pad:
154
155
156
157 68/push _test-output-stream/imm32
158
159 e8/call clear-stream/disp32
160
161 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
162
163
164 68/push _test-output-buffered-file->buffer/imm32
165
166 e8/call clear-stream/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
169
170
171 68/push 2/imm32
172 68/push 0xab/imm32
173 68/push _test-output-buffered-file/imm32
174
175 e8/call emit-hex/disp32
176
177 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
178
179
180 68/push _test-output-buffered-file/imm32
181
182 e8/call flush/disp32
183
184 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
185
186
187 68/push "F - test-emit-hex-zero-pad/1"/imm32
188 68/push "ab 00 "/imm32
189 68/push _test-output-stream/imm32
190
191 e8/call check-stream-equal/disp32
192
193 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
194
195 c3/return
196
197 test-emit-hex-negative:
198
199
200
201 68/push _test-output-stream/imm32
202
203 e8/call clear-stream/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
206
207
208 68/push _test-output-buffered-file->buffer/imm32
209
210 e8/call clear-stream/disp32
211
212 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
213
214
215 68/push 2/imm32
216 68/push -1/imm32
217 68/push _test-output-buffered-file/imm32
218
219 e8/call emit-hex/disp32
220
221 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
222
223
224 68/push _test-output-buffered-file/imm32
225
226 e8/call flush/disp32
227
228 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
229
230
231 68/push "F - test-emit-hex-negative/1"/imm32
232 68/push "ff ff "/imm32
233 68/push _test-output-stream/imm32
234
235 e8/call check-stream-equal/disp32
236
237 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
238
239 c3/return
240
241