https://github.com/akkartik/mu/blob/master/subx/071hex.subx
1
2
3
4 == code
5
6
7
8
9
10
11 e8/call run-tests/disp32
12
13 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
14 b8/copy-to-EAX 1/imm32/exit
15 cd/syscall 0x80/imm8
16
17 is-hex-int?:
18
19 55/push-EBP
20 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
21
22 51/push-ECX
23 52/push-EDX
24 53/push-EBX
25
26 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 8/disp8 .
27
28 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 .
29
30 8b/copy 0/mod/indirect 1/rm32/ECX . . . 1/r32/ECX . .
31
32 b8/copy-to-EAX 0/imm32/false
33 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . .
34 7d/jump-if-greater-or-equal $is-hex-int?:end/disp8
35
36 $is-hex-int?:initial-0:
37
38 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . .
39 8a/copy-byte 0/mod/indirect 1/rm32/ECX . . . 3/r32/BL . .
40 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0x30/imm32/0
41 75/jump-if-not-equal $is-hex-int?:loop/disp8
42
43 41/increment-ECX
44 $is-hex-int?:initial-0x:
45
46 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . .
47 7d/jump-if-greater-or-equal $is-hex-int?:true/disp8
48
49 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . .
50 8a/copy-byte 0/mod/indirect 1/rm32/ECX . . . 3/r32/BL . .
51 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0x78/imm32/x
52 75/jump-if-not-equal $is-hex-int?:loop/disp8
53
54 41/increment-ECX
55 $is-hex-int?:loop:
56
57 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . .
58 7d/jump-if-greater-or-equal $is-hex-int?:true/disp8
59
60
61 8a/copy-byte 0/mod/indirect 1/rm32/ECX . . . 0/r32/AL . .
62 50/push-EAX
63
64 e8/call is-hex-byte?/disp32
65
66 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
67
68 3d/compare-with-EAX 0/imm32
69 74/jump-if-equal $is-hex-int?:end/disp8
70
71 41/increment-ECX
72
73 eb/jump $is-hex-int?:loop/disp8
74 $is-hex-int?:true:
75
76 b8/copy-to-EAX 1/imm32/true
77 $is-hex-int?:end:
78
79 5b/pop-to-EBX
80 5a/pop-to-EDX
81 59/pop-to-ECX
82
83 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
84 5d/pop-to-EBP
85 c3/return
86
87 test-is-hex-int:
88
89 55/push-EBP
90 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
91
92 68/push _test-slice-hex-int-end/imm32
93 68/push _test-slice-hex-int/imm32
94 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
95
96
97 51/push-ECX
98
99 e8/call is-hex-int?/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
102
103
104 68/push "F - test-is-hex-int"/imm32
105 68/push 1/imm32/true
106 50/push-EAX
107
108 e8/call check-ints-equal/disp32
109
110 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
111
112 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
113 5d/pop-to-EBP
114 c3/return
115
116 test-is-hex-int-handles-letters:
117
118 55/push-EBP
119 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
120
121 68/push _test-slice-hex-int-letters-end/imm32
122 68/push _test-slice-hex-int-letters/imm32
123 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
124
125
126 51/push-ECX
127
128 e8/call is-hex-int?/disp32
129
130 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
131
132
133 68/push "F - test-is-hex-int-handles-letters"/imm32
134 68/push 1/imm32/true
135 50/push-EAX
136
137 e8/call check-ints-equal/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
140
141 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
142 5d/pop-to-EBP
143 c3/return
144
145 test-is-hex-int-with-trailing-char:
146
147 55/push-EBP
148 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
149
150 68/push _test-slice-digits-and-char-end/imm32
151 68/push _test-slice-digits-and-char/imm32
152 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
153
154
155 51/push-ECX
156
157 e8/call is-hex-int?/disp32
158
159 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
160
161
162 68/push "F - test-is-hex-int-with-trailing-char"/imm32
163 68/push 0/imm32/false
164 50/push-EAX
165
166 e8/call check-ints-equal/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
169
170 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
171 5d/pop-to-EBP
172 c3/return
173
174 test-is-hex-int-with-leading-char:
175
176 55/push-EBP
177 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
178
179 68/push _test-slice-char-and-digits-end/imm32
180 68/push _test-slice-char-and-digits/imm32
181 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
182
183
184 51/push-ECX
185
186 e8/call is-hex-int?/disp32
187
188 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
189
190
191 68/push "F - test-is-hex-int-with-leading-char"/imm32
192 68/push 0/imm32/false
193 50/push-EAX
194
195 e8/call check-ints-equal/disp32
196
197 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
198
199 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
200 5d/pop-to-EBP
201 c3/return
202
203 test-is-hex-int-empty:
204
205 55/push-EBP
206 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
207
208 68/push _test-slice-empty-end/imm32
209 68/push _test-slice-empty/imm32
210 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
211
212
213 51/push-ECX
214
215 e8/call is-hex-int?/disp32
216
217 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
218
219
220 68/push "F - test-is-hex-int-empty"/imm32
221 68/push 0/imm32/false
222 50/push-EAX
223
224 e8/call check-ints-equal/disp32
225
226 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
227
228 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
229 5d/pop-to-EBP
230 c3/return
231
232 test-is-hex-int-handles-0x-prefix:
233
234 55/push-EBP
235 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
236
237 68/push _test-slice-hex-int-with-0x-prefix-end/imm32
238 68/push _test-slice-hex-int-with-0x-prefix/imm32
239 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
240
241
242 51/push-ECX
243
244 e8/call is-hex-int?/disp32
245
246 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
247
248
249 68/push "F - test-is-hex-int-handles-0x-prefix"/imm32
250 68/push 1/imm32/true
251 50/push-EAX
252
253 e8/call check-ints-equal/disp32
254
255 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
256
257 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
258 5d/pop-to-EBP
259 c3/return
260
261 is-hex-byte?:
262
263 55/push-EBP
264 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
265
266 51/push-ECX
267
268 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 8/disp8 .
269
270 b8/copy-to-EAX 0/imm32/false
271 81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0x30/imm32
272 7c/jump-if-lesser $is-hex-byte?:end/disp8
273
274 81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0x66/imm32
275 7f/jump-if-greater $is-hex-byte?:end/disp8
276
277 b8/copy-to-EAX 1/imm32/true
278 81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0x39/imm32
279 7e/jump-if-lesser-or-equal $is-hex-byte?:end/disp8
280
281 81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0x61/imm32
282 7d/jump-if-greater-or-equal $is-hex-byte?:end/disp8
283
284 b8/copy-to-EAX 0/imm32/false
285 $is-hex-byte?:end:
286
287 59/pop-to-ECX
288
289 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
290 5d/pop-to-EBP
291 c3/return
292
293 test-hex-below-0:
294
295
296 68/push 0x2f/imm32
297
298 e8/call is-hex-byte?/disp32
299
300 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
301
302
303 68/push "F - test-hex-below-0"/imm32
304 68/push 0/imm32/false
305 50/push-EAX
306
307 e8/call check-ints-equal/disp32
308
309 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
310 c3/return
311
312 test-hex-0-to-9:
313
314
315 68/push 0x30/imm32
316
317 e8/call is-hex-byte?/disp32
318
319 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
320
321
322 68/push "F - test-hex-at-0"/imm32
323 68/push 1/imm32/true
324 50/push-EAX
325
326 e8/call check-ints-equal/disp32
327
328 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
329
330
331 68/push 0x39/imm32
332
333 e8/call is-hex-byte?/disp32
334
335 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
336
337
338 68/push "F - test-hex-at-9"/imm32
339 68/push 1/imm32/true
340 50/push-EAX
341
342 e8/call check-ints-equal/disp32
343
344 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
345 c3/return
346
347 test-hex-above-9-to-a:
348
349
350 68/push 0x3a/imm32
351
352 e8/call is-hex-byte?/disp32
353
354 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
355
356
357 68/push "F - test-hex-above-9-to-a"/imm32
358 68/push 0/imm32/false
359 50/push-EAX
360
361 e8/call check-ints-equal/disp32
362
363 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
364 c3/return
365
366 test-hex-a-to-f:
367
368
369 68/push 0x61/imm32
370
371 e8/call is-hex-byte?/disp32
372
373 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
374
375
376 68/push "F - test-hex-at-a"/imm32
377 68/push 1/imm32/true
378 50/push-EAX
379
380 e8/call check-ints-equal/disp32
381
382 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
383
384
385 68/push 0x66/imm32
386
387 e8/call is-hex-byte?/disp32
388
389 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
390
391
392 68/push "F - test-hex-at-f"/imm32
393 68/push 1/imm32/true
394 50/push-EAX
395
396 e8/call check-ints-equal/disp32
397
398 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
399 c3/return
400
401 test-hex-above-f:
402
403
404 68/push 0x67/imm32
405
406 e8/call is-hex-byte?/disp32
407
408 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
409
410
411 68/push "F - test-hex-above-f"/imm32
412 68/push 0/imm32/false
413 50/push-EAX
414
415 e8/call check-ints-equal/disp32
416
417 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
418 c3/return
419
420 parse-hex-digit:
421
422
423 3d/compare-EAX 0x39/imm32/9
424 7f/jump-if-greater $parse-hex-digit:else/disp8
425 2d/subtract-from-EAX 0x30/imm32/0
426 c3/return
427 $parse-hex-digit:else:
428
429 2d/subtract-from-EAX 0x57/imm32/a-10
430 c3/return
431
432 == data
433
434 _test-slice-empty:
435
436 _test-slice-empty-end:
437
438 _test-slice-hex-int:
439 33/3 34/4
440 _test-slice-hex-int-end:
441
442 _test-slice-hex-int-with-0x-prefix:
443 30/0 78/x 33/3 34/4
444 _test-slice-hex-int-with-0x-prefix-end:
445
446 _test-slice-hex-int-letters:
447 33/3 34/4 61/a
448 _test-slice-hex-int-letters-end:
449
450 _test-slice-char-and-digits:
451 71/q 33/3 34/4
452 _test-slice-char-and-digits-end:
453
454 _test-slice-digits-and-char:
455 33/3 34/4 71/q
456 _test-slice-digits-and-char-end:
457
458