interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / rung3 / om3.s

2118 lines · 39686 bytes Raw Blame History
1; om3.s -- rung 3 of the Omega seed chain: a translator from a subset of Omegese to AArch64 machine
2; words, written in asm2's language (seed/rung2) and built by asm2:
3; cat seed/rung2/table.s2 seed/rung3/table3.s2 seed/rung3/om3.s | seed/rung2/asm2.bin > om3.bin
4; Use: om3.bin < task.omegese > code.bin. The output is the function's words only (word 0 = entry), to be
5; called under the OSC-1 native rules (docs/osc/OSC-1-DESIGN.md section 7): parameters in x0..x5, result
6; in x0 in canonical form, OscRt * in x7, a trap calls OscRt.trap (offset 16) with x0 = rt, x1 = code.
7;
8; The subset (what the 10 dev tasks use): one function; types bool uchar ushort uint ulong byte short int
9; long (and u8 .. i64); statements name [=] value, if/else/end, while c [bound N], for i T <number>, ret v;
10; values: names, numbers, typed numbers, conversions, add sub mul div rem and or xor shl shr, eq ne lt le
11; gt ge, neg, not, ( v ). Refused (error 9): signed div/rem, signed shl, bool conversions, a for count that
12; is not a number, void, break, trap, arrays, calls, more than one function.
13; Semantics follow the C path's interpreter (src/compiler/osc_interp.c): unsigned ops wrap to the width,
14; signed add/sub/mul/neg trap 1 on overflow, div/rem trap 2 on zero, a loop bound trap 4, a conversion out
15; of range trap 5, a shift amount outside 0..width-1 trap 7.
16;
17; Code generation: every name lives in its own register for its whole scope (the C back end keeps every
18; value in a stack slot, OSC-1 section 7); temporaries are registers freed at the end of each statement.
19; Registers handed out: x0..x6 not taken by parameters, x8..x15, x17 (never x7 = rt, x16, x18, x19..x30).
20;
21; Every machine word om3 writes is built from a fixed part read from the encoding diagram of the Arm ARM
22; DDI 0487 M.d section named beside it, ORed with register and number fields.
23;
24; om3's own registers: x19 input cursor, x20 output cursor, x21 output start, x22 line number,
25; x23 names in scope, x24 next free pool slot, x25 block stack top, x26 trap list end, x27 return type
26; (0 before fn), x28 pool slots held by names, x29 pool start (after the parameter registers).
27; Memory: input 0x500000, output 0x600000, names 0x700000 (16 bytes: packed name, register, type),
28; blocks 0x710000 (64 bytes), trap list 0x720000 (8 bytes: site, code), message 0x730000.
29; Errors: "om3: line N: error E" on stderr, exit E: 1 read, 2 write, 3 unknown name, 4 line ends too
30; early, 5 extra words, 6 bad number, 7 type mismatch, 8 number out of range for its type, 9 not in the
31; rung-3 subset, 10 name defined twice, 11 number with no type, 12 out of registers, 13 word over 8
32; characters, 14 table full, 15 block structure, 16 syntax.
33;
34; ---- ELF-64 file header (words as in seed/rung0/seed0.hex) ----
35 .w 0x464c457f
36 .w 0x00010102
37 .w 0x00000000
38 .w 0x00000000
39 .w 0x00b70002
40 .w 0x00000001
41 .w 0x00400078
42 .w 0x00000000
43 .w 0x00000040
44 .w 0x00000000
45 .w 0x00000000
46 .w 0x00000000
47 .w 0x00000000
48 .w 0x00380040
49 .w 0x00000001
50 .w 0x00000000
51; ---- program header: one PT_LOAD, read/write/execute, file at 0x400000 ----
52 .w 0x00000001
53 .w 0x00000007
54 .w 0x00000000
55 .w 0x00000000
56 .w 0x00400000
57 .w 0x00000000
58 .w 0x00400000
59 .w 0x00000000
60 .w 0x00001bb4 ; p_filesz = 7092 bytes, the size of om3.bin (asm2 has no size arithmetic; gate3.sh checks it)
61 .w 0x00000000
62 .w 0x00340000 ; p_memsz: up to 0x740000
63 .w 0x00000000
64 .w 0x00001000
65 .w 0x00000000
66; ---- 0x400078: entry ----
67 b START
68 .w 0
69; ---- 0x400080: keyword table, 16 bytes per entry: packed word (8), code (4), 0 (4); made with
70; evidence/SEED-0/rung3-worksheet.sh. Codes: 1..9 types, 33..50 ops, 64.. statements, 77 not in subset.
71:KWTAB
72 .w 0x6c6f6f62
73 .w 0x00000000
74 .w 1
75 .w 0
76 .w 0x61686375
77 .w 0x00000072
78 .w 2
79 .w 0
80 .w 0x00003875
81 .w 0x00000000
82 .w 2
83 .w 0
84 .w 0x6f687375
85 .w 0x00007472
86 .w 3
87 .w 0
88 .w 0x00363175
89 .w 0x00000000
90 .w 3
91 .w 0
92 .w 0x746e6975
93 .w 0x00000000
94 .w 4
95 .w 0
96 .w 0x00323375
97 .w 0x00000000
98 .w 4
99 .w 0
100 .w 0x6e6f6c75
101 .w 0x00000067
102 .w 5
103 .w 0
104 .w 0x00343675
105 .w 0x00000000
106 .w 5
107 .w 0
108 .w 0x65747962
109 .w 0x00000000
110 .w 6
111 .w 0
112 .w 0x00003869
113 .w 0x00000000
114 .w 6
115 .w 0
116 .w 0x726f6873
117 .w 0x00000074
118 .w 7
119 .w 0
120 .w 0x00363169
121 .w 0x00000000
122 .w 7
123 .w 0
124 .w 0x00746e69
125 .w 0x00000000
126 .w 8
127 .w 0
128 .w 0x00323369
129 .w 0x00000000
130 .w 8
131 .w 0
132 .w 0x676e6f6c
133 .w 0x00000000
134 .w 9
135 .w 0
136 .w 0x00343669
137 .w 0x00000000
138 .w 9
139 .w 0
140 .w 0x00646461
141 .w 0x00000000
142 .w 33
143 .w 0
144 .w 0x00627573
145 .w 0x00000000
146 .w 34
147 .w 0
148 .w 0x006c756d
149 .w 0x00000000
150 .w 35
151 .w 0
152 .w 0x00766964
153 .w 0x00000000
154 .w 36
155 .w 0
156 .w 0x006d6572
157 .w 0x00000000
158 .w 37
159 .w 0
160 .w 0x00646e61
161 .w 0x00000000
162 .w 38
163 .w 0
164 .w 0x0000726f
165 .w 0x00000000
166 .w 39
167 .w 0
168 .w 0x00726f78
169 .w 0x00000000
170 .w 40
171 .w 0
172 .w 0x006c6873
173 .w 0x00000000
174 .w 41
175 .w 0
176 .w 0x00726873
177 .w 0x00000000
178 .w 42
179 .w 0
180 .w 0x00007165
181 .w 0x00000000
182 .w 43
183 .w 0
184 .w 0x0000656e
185 .w 0x00000000
186 .w 44
187 .w 0
188 .w 0x0000746c
189 .w 0x00000000
190 .w 45
191 .w 0
192 .w 0x0000656c
193 .w 0x00000000
194 .w 46
195 .w 0
196 .w 0x00007467
197 .w 0x00000000
198 .w 47
199 .w 0
200 .w 0x00006567
201 .w 0x00000000
202 .w 48
203 .w 0
204 .w 0x0067656e
205 .w 0x00000000
206 .w 49
207 .w 0
208 .w 0x00746f6e
209 .w 0x00000000
210 .w 50
211 .w 0
212 .w 0x00006e66
213 .w 0x00000000
214 .w 64
215 .w 0
216 .w 0x00006f74
217 .w 0x00000000
218 .w 65
219 .w 0
220 .w 0x00646e65
221 .w 0x00000000
222 .w 66
223 .w 0
224 .w 0x00006669
225 .w 0x00000000
226 .w 67
227 .w 0
228 .w 0x65736c65
229 .w 0x00000000
230 .w 68
231 .w 0
232 .w 0x6c696877
233 .w 0x00000065
234 .w 69
235 .w 0
236 .w 0x6e756f62
237 .w 0x00000064
238 .w 70
239 .w 0
240 .w 0x00726f66
241 .w 0x00000000
242 .w 71
243 .w 0
244 .w 0x00746572
245 .w 0x00000000
246 .w 72
247 .w 0
248 .w 0x0000003d
249 .w 0x00000000
250 .w 73
251 .w 0
252 .w 0x00000028
253 .w 0x00000000
254 .w 74
255 .w 0
256 .w 0x00000029
257 .w 0x00000000
258 .w 75
259 .w 0
260 .w 0x64696f76
261 .w 0x00000000
262 .w 76
263 .w 0
264 .w 0x61657262
265 .w 0x0000006b
266 .w 77
267 .w 0
268 .w 0x70617274
269 .w 0x00000000
270 .w 77
271 .w 0
272 .w 0x00747570
273 .w 0x00000000
274 .w 77
275 .w 0
276 .w 0x65657266
277 .w 0x00000000
278 .w 77
279 .w 0
280 .w 0x00746567
281 .w 0x00000000
282 .w 77
283 .w 0
284 .w 0x0077656e
285 .w 0x00000000
286 .w 77
287 .w 0
288 .w 0x006e776f
289 .w 0x00000000
290 .w 77
291 .w 0
292 .w 0x74696465
293 .w 0x00000000
294 .w 77
295 .w 0
296 .w 0x77656976
297 .w 0x00000000
298 .w 77
299 .w 0
300 .w 0x65757274
301 .w 0x00000000
302 .w 77
303 .w 0
304 .w 0x736c6166
305 .w 0x00000065
306 .w 77
307 .w 0
308 .w 0
309 .w 0
310 .w 0
311 .w 0
312; ---- messages ("om3: line ", ": error "), NUL-ended ----
313:MSG1
314 .w 0x3a336d6f
315 .w 0x6e696c20
316 .w 0x00002065
317:MSG2
318 .w 0x7265203a
319 .w 0x20726f72
320 .w 0x00000000
321; ---- register pool: x0..x6, x8..x15, x17; the pool starts after the parameter registers ----
322:POOLC
323 .b 0
324 .b 1
325 .b 2
326 .b 3
327 .b 4
328 .b 5
329 .b 6
330 .b 8
331 .b 9
332 .b 10
333 .b 11
334 .b 12
335 .b 13
336 .b 14
337 .b 15
338 .b 17
339:POOLEND
340; ---- width in bits by type code 0..9 (bool 1) ----
341:TWID
342 .b 0
343 .b 1
344 .b 8
345 .b 16
346 .b 32
347 .b 64
348 .b 8
349 .b 16
350 .b 32
351 .b 64
352; ---- condition for eq ne lt le gt ge, unsigned then signed (Arm ARM Table C1-1, C1.2.4):
353; EQ 0, NE 1, LO 3 / LT 11, LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10. The opposite condition is cond ^ 1.
354:CONDS
355 .b 0
356 .b 0
357 .b 1
358 .b 1
359 .b 3
360 .b 11
361 .b 9
362 .b 13
363 .b 8
364 .b 12
365 .b 2
366 .b 10
367 .b 0 ; pad to a word boundary
368 .b 0
369; ======================================================================================================
370; start: read all of stdin to 0x500000 (at most 1 MiB - 1 bytes), NUL at the end
371:START
372 movz.x x19 0x50 1
373 movz.x x12 0 0
374:RD
375 movz.x x0 0 0
376 add.x x1 x19 x12
377 movz.x x2 0x10 1
378 sub.x.i x2 x2 1
379 sub.x x2 x2 x12
380 cbz.x x2 E_FULL
381 movz.x x8 63 0
382 svc 0
383 cmp.x.i x0 0
384 b.eq RDDONE
385 b.lt E_READ
386 add.x x12 x12 x0
387 b RD
388:RDDONE
389 add.x x0 x19 x12
390 strb wzr x0 0
391 movz.x x20 0x60 1
392 mov.x x21 x20
393 movz.x x22 1 0
394 movz.x x23 0 0
395 movz.x x24 0 0
396 movz.x x25 0x71 1
397 movz.x x26 0x72 1
398 movz.x x27 0 0
399 movz.x x28 0 0
400 adr x29 POOLC
401; ---- one statement per line ----
402:STMT
403 mov.x x24 x28
404 bl TOK
405 cbz.x x0 STMT
406 cmp.x.i x0 3
407 b.eq E_BLOCK
408 cmp.x.i x0 2
409 b.eq E_SYNTAX
410 cmp.x.i x2 8
411 b.hi E_LONG
412 mov.x x12 x1
413 bl KW
414 cmp.x.i x0 64
415 b.eq S_FN
416 cbz.x x27 E_SYNTAX
417 cbz.x x0 S_ASSIGN
418 cmp.x.i x0 66
419 b.eq S_END
420 cmp.x.i x0 67
421 b.eq S_IF
422 cmp.x.i x0 68
423 b.eq S_ELSE
424 cmp.x.i x0 69
425 b.eq S_WHILE
426 cmp.x.i x0 71
427 b.eq S_FOR
428 cmp.x.i x0 72
429 b.eq S_RET
430 cmp.x.i x0 77
431 b.eq E_SUBSET
432 b E_SYNTAX
433; ---- fn name (param type)* to type ----
434:S_FN
435 cbnz.x x27 E_SUBSET
436 bl TOK
437 cmp.x.i x0 1
438 b.ne E_SYNTAX
439 movz.x x13 0 0
440:FN_P
441 bl TOK
442 cbz.x x0 E_FEW
443 cmp.x.i x0 1
444 b.ne E_SYNTAX
445 cmp.x.i x2 8
446 b.hi E_LONG
447 mov.x x12 x1
448 bl KW
449 cmp.x.i x0 65
450 b.eq FN_TO
451 cbnz.x x0 E_SYNTAX
452 mov.x x1 x12
453 bl FINDNAME
454 cbnz.x x0 E_TWICE
455 bl TYPEWORD
456 cmp.x.i x13 6
457 b.hs E_SUBSET
458 mov.x x3 x0
459 mov.x x1 x12
460 mov.x x2 x13
461 bl ADDNAME
462 add.x.i x13 x13 1
463 b FN_P
464:FN_TO
465 bl TYPEWORD
466 mov.x x27 x0
467 add.x x29 x29 x13
468 movz.x x24 0 0
469 movz.x x28 0 0
470 bl EOL
471 b STMT
472; ---- name [=] value ----
473:S_ASSIGN
474 sub.x.i sp sp 32
475 str.x x12 sp 0
476 bl TOK
477 mov.x x3 x0
478 mov.x x4 x1
479 mov.x x5 x2
480 cmp.x.i x3 1
481 b.ne SA1
482 cmp.x.i x5 8
483 b.hi SA1
484 mov.x x1 x4
485 bl KW
486 cmp.x.i x0 73
487 b.ne SA1
488 bl TOK
489 mov.x x3 x0
490 mov.x x4 x1
491 mov.x x5 x2
492:SA1
493 ldr.x x1 sp 0
494 bl FINDNAME
495 cbz.x x0 SA_NEW
496 ldr.w w1 x0 2
497 str.x x1 sp 1
498 ldr.w w0 x0 3
499 str.x x0 sp 2
500 bl VALTOK
501 ldr.x x9 sp 2
502 cmp.x x2 x9
503 b.ne E_TYPE
504 ldr.x x3 sp 1
505 bl FORCE
506 b SA_END
507:SA_NEW
508 bl ALLOC
509 mov.x x28 x24
510 str.x x0 sp 1
511 mov.x x1 x0
512 movz.x x0 0 0
513 bl VALTOK
514 cmp.x.i x0 2
515 b.eq E_BARE
516 str.x x2 sp 2
517 ldr.x x3 sp 1
518 bl FORCE
519 ldr.x x1 sp 0
520 ldr.x x2 sp 1
521 ldr.x x3 sp 2
522 bl ADDNAME
523:SA_END
524 add.x.i sp sp 32
525 bl EOL
526 b STMT
527; ---- ret value: the value into x0, then RET ----
528:S_RET
529 mov.x x0 x27
530 movz.x x1 0 0
531 bl VAL
532 cmp.x x2 x27
533 b.ne E_TYPE
534 movz.x x3 0 0
535 bl FORCE
536 movz.x x0 0x03c0 0
537 movk.x x0 0xd65f 1 ; RET (X30), C6.2.338
538 bl EMIT
539 bl EOL
540 b STMT
541; ---- if cond ----
542:S_IF
543 bl COND
544 movz.x x1 1 0
545 movz.x x2 0 0
546 movz.x x3 0 0
547 movz.x x4 0 0
548 mov.x x5 x23
549 mov.x x6 x28
550 bl PUSHB
551 bl EOL
552 b STMT
553; ---- else: jump over the else part; the if's false branch lands after that jump ----
554:S_ELSE
555 movz.x x9 0x71 1
556 cmp.x x25 x9
557 b.eq E_BLOCK
558 sub.x.i x10 x25 64
559 ldr.x x0 x10 0
560 cmp.x.i x0 1
561 b.ne E_BLOCK
562 mov.x x11 x20
563 movz.x x0 0x1400 1 ; B (distance filled at end), C6.2.35
564 bl EMIT
565 ldr.x x0 x10 1
566 mov.x x1 x20
567 bl PATCH19
568 movz.x x0 2 0
569 str.x x0 x10 0
570 str.x x11 x10 1
571 ldr.x x23 x10 5
572 ldr.x x28 x10 6
573 bl EOL
574 b STMT
575; ---- while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4;
576; counter = counter + 1; body; B head ----
577:S_WHILE
578 sub.x.i sp sp 64
579 str.x x23 sp 0
580 str.x x28 sp 1
581 bl ALLOC
582 mov.x x28 x24
583 str.x x0 sp 2
584 movz.x x9 0xd280 1 ; MOVZ Xc, #0, C6.2.285
585 orr.x x0 x0 x9
586 bl EMIT
587 str.x x20 sp 3
588 bl COND
589 str.x x0 sp 4
590 movz.x x9 0x4240 0
591 movk.x x9 0x000f 1
592 str.x x9 sp 5
593 bl TOK
594 cbz.x x0 SW_NOB
595 cmp.x.i x0 3
596 b.eq SW_NOB
597 cmp.x.i x0 1
598 b.ne E_EXTRA
599 cmp.x.i x2 8
600 b.hi E_EXTRA
601 bl KW
602 cmp.x.i x0 70
603 b.ne E_EXTRA
604 bl TOK
605 cbz.x x0 E_FEW
606 cmp.x.i x0 2
607 b.ne E_SYNTAX
608 sub.x.i x9 x1 1
609 movz.x x10 0x423f 0
610 movk.x x10 0x000f 1
611 cmp.x x9 x10
612 b.hs E_RANGE
613 str.x x1 sp 5
614 bl EOL
615:SW_NOB
616 ldr.x x1 sp 5
617 movz.x x9 4095 0
618 cmp.x x1 x9
619 b.hi SW_BIG
620 movz.x x0 0x001f 0
621 movk.x x0 0xf100 1 ; CMP Xc, #N = SUBS XZR, Xc, #N, C6.2.96
622 ubfm.x x1 x1 54 53
623 orr.x x0 x0 x1
624 ldr.x x1 sp 2
625 ubfm.x x1 x1 59 58
626 orr.x x0 x0 x1
627 bl EMIT
628 b SW_G
629:SW_BIG
630 bl ALLOC
631 mov.x x13 x0
632 ldr.x x1 sp 5
633 bl MATCONST
634 movz.x x0 0x001f 0
635 movk.x x0 0xeb00 1 ; CMP Xc, Xn = SUBS XZR, Xc, Xn, C6.2.97
636 ldr.x x1 sp 2
637 ubfm.x x1 x1 59 58
638 orr.x x0 x0 x1
639 ubfm.x x1 x13 48 47
640 orr.x x0 x0 x1
641 bl EMIT
642:SW_G
643 movz.x x0 2 0
644 movz.x x1 4 0
645 bl TRAPC
646 movz.x x0 0x0400 0
647 movk.x x0 0x9100 1 ; ADD Xc, Xc, #1, C6.2.5
648 ldr.x x1 sp 2
649 orr.x x0 x0 x1
650 ubfm.x x1 x1 59 58
651 orr.x x0 x0 x1
652 bl EMIT
653 ldr.x x0 sp 4
654 movz.x x1 3 0
655 ldr.x x2 sp 3
656 ldr.x x3 sp 2
657 movz.x x4 0 0
658 ldr.x x5 sp 0
659 ldr.x x6 sp 1
660 bl PUSHB
661 add.x.i sp sp 64
662 b STMT
663; ---- for i T K (K a number): i = 0; head: not i < K -> exit; body; latch i = add i 1; B head ----
664:S_FOR
665 sub.x.i sp sp 64
666 str.x x23 sp 0
667 str.x x28 sp 1
668 bl TOK
669 cbz.x x0 E_FEW
670 cmp.x.i x0 1
671 b.ne E_SYNTAX
672 cmp.x.i x2 8
673 b.hi E_LONG
674 str.x x1 sp 2
675 bl KW
676 cbnz.x x0 E_SYNTAX
677 ldr.x x1 sp 2
678 bl FINDNAME
679 cbnz.x x0 E_TWICE
680 bl TYPEWORD
681 str.x x0 sp 3
682 cmp.x.i x0 1
683 b.eq E_TYPE
684 bl TOK
685 cbz.x x0 E_FEW
686 cmp.x.i x0 2
687 b.ne E_SUBSET
688 ldr.x x2 sp 3
689 bl RANGE
690 str.x x1 sp 4
691 bl EOL
692 bl ALLOC
693 mov.x x28 x24
694 str.x x0 sp 5
695 mov.x x2 x0
696 ldr.x x1 sp 2
697 ldr.x x3 sp 3
698 bl ADDNAME
699 ldr.x x0 sp 5
700 movz.x x9 0xd280 1 ; MOVZ Xi, #0, C6.2.285
701 orr.x x0 x0 x9
702 bl EMIT
703 str.x x20 sp 6
704 ldr.x x1 sp 4
705 movz.x x9 4095 0
706 cmp.x x1 x9
707 b.hi SF_BIG
708 movz.x x0 0x001f 0
709 movk.x x0 0xf100 1 ; CMP Xi, #K, C6.2.96
710 ubfm.x x1 x1 54 53
711 orr.x x0 x0 x1
712 ldr.x x1 sp 5
713 ubfm.x x1 x1 59 58
714 orr.x x0 x0 x1
715 bl EMIT
716 b SF_B
717:SF_BIG
718 bl ALLOC
719 mov.x x13 x0
720 ldr.x x1 sp 4
721 bl MATCONST
722 movz.x x0 0x001f 0
723 movk.x x0 0xeb00 1 ; CMP Xi, Xk, C6.2.97
724 ldr.x x1 sp 5
725 ubfm.x x1 x1 59 58
726 orr.x x0 x0 x1
727 ubfm.x x1 x13 48 47
728 orr.x x0 x0 x1
729 bl EMIT
730:SF_B
731 mov.x x13 x20
732 movz.x x0 0x5400 1 ; B.HS (unsigned) or B.GE (signed) to the exit, C6.2.34
733 ldr.x x9 sp 3
734 movz.x x1 2 0
735 cmp.x.i x9 6
736 b.lo SF1
737 movz.x x1 10 0
738:SF1
739 orr.x x0 x0 x1
740 bl EMIT
741 mov.x x0 x13
742 movz.x x1 4 0
743 ldr.x x2 sp 6
744 ldr.x x3 sp 5
745 ldr.x x4 sp 3
746 ldr.x x5 sp 0
747 ldr.x x6 sp 1
748 bl PUSHB
749 add.x.i sp sp 64
750 b STMT
751; ---- end: close the innermost block, or the function ----
752:S_END
753 movz.x x9 0x71 1
754 cmp.x x25 x9
755 b.eq FINISH
756 sub.x.i x25 x25 64
757 ldr.x x0 x25 0
758 cmp.x.i x0 1
759 b.eq SE_IF
760 cmp.x.i x0 2
761 b.eq SE_ELSE
762 cmp.x.i x0 3
763 b.eq SE_WHILE
764 sub.x.i sp sp 48
765 movz.x x0 1 0
766 str.x x0 sp 0
767 ldr.x x0 x25 3
768 str.x x0 sp 1
769 ldr.x x0 x25 4
770 str.x x0 sp 2
771 movz.x x0 3 0
772 str.x x0 sp 3
773 movz.x x0 1 0
774 str.x x0 sp 4
775 ldr.x x0 x25 4
776 str.x x0 sp 5
777 movz.x x0 33 0
778 ldr.x x1 x25 3
779 add.x.i x2 sp 0
780 bl BINOP
781 add.x.i sp sp 48
782:SE_WHILE
783 ldr.x x0 x25 2
784 bl BACK
785:SE_IF
786 ldr.x x0 x25 1
787 mov.x x1 x20
788 bl PATCH19
789 b SE_X
790:SE_ELSE
791 ldr.x x0 x25 1
792 mov.x x1 x20
793 bl PATCH26
794:SE_X
795 ldr.x x23 x25 5
796 ldr.x x28 x25 6
797 bl EOL
798 b STMT
799; ---- end of the function: trap stubs, then write the words ----
800; shared tail: MOV X0, X7; LDR X16, [X7, #16]; BR X16. Per trap code used: MOVZ X1, #code; B tail.
801:FINISH
802 bl EOL
803 movz.x x9 0x72 1
804 cmp.x x26 x9
805 b.eq FI_T
806 mov.x x13 x20
807 movz.x x0 0x03e0 0
808 movk.x x0 0xaa07 1 ; MOV X0, X7 = ORR X0, XZR, X7, C6.2.282
809 bl EMIT
810 movz.x x0 0x08f0 0
811 movk.x x0 0xf940 1 ; LDR X16, [X7, #16], unsigned offset imm12 = 2, C6.2.216
812 bl EMIT
813 movz.x x0 0x0200 0
814 movk.x x0 0xd61f 1 ; BR X16, C6.2.46
815 bl EMIT
816 movz.x x14 1 0
817:FI_C
818 movz.x x15 0 0
819 movz.x x12 0x72 1
820:FI_S
821 cmp.x x12 x26
822 b.hs FI_N
823 ldr.w w0 x12 1
824 cmp.x x0 x14
825 b.ne FI_NX
826 cbnz.x x15 FI_P
827 mov.x x15 x20
828 movz.x x0 0x0001 0
829 movk.x x0 0xd280 1 ; MOVZ X1, #code, C6.2.285
830 ubfm.x x1 x14 59 58
831 orr.x x0 x0 x1
832 bl EMIT
833 mov.x x0 x13
834 bl BACK
835:FI_P
836 ldr.w w0 x12 0
837 mov.x x1 x15
838 bl PATCH19
839:FI_NX
840 add.x.i x12 x12 8
841 b FI_S
842:FI_N
843 add.x.i x14 x14 1
844 cmp.x.i x14 14
845 b.ls FI_C
846:FI_T
847 bl TOK
848 cbz.x x0 FI_T
849 cmp.x.i x0 3
850 b.ne E_SUBSET
851 mov.x x12 x21
852:WR
853 sub.x x2 x20 x12
854 cbz.x x2 EXIT0
855 movz.x x0 1 0
856 mov.x x1 x12
857 movz.x x8 64 0
858 svc 0
859 cmp.x.i x0 0
860 b.le E_WRITE
861 add.x x12 x12 x0
862 b WR
863:EXIT0
864 movz.x x0 0 0
865 movz.x x8 93 0
866 svc 0
867; ======================================================================================================
868; VAL: read one value. x0 expected type (0 none), x1 destination register (255 none).
869; Out: x0 kind (1 register, 2 bare number, 3 typed number, 4 flags), x1 register / number / condition,
870; x2 type. Only the outermost op writes the destination. Clobbers x0..x17.
871:VAL
872 str.x.pre x30 sp -32
873 str.x x0 sp 1
874 str.x x1 sp 2
875 bl TOK
876 mov.x x3 x0
877 mov.x x4 x1
878 mov.x x5 x2
879 ldr.x x0 sp 1
880 ldr.x x1 sp 2
881 ldr.x.post x30 sp 32
882; VALTOK: the same with the first word already read (x3 kind, x4 word or number, x5 length).
883; Frame (8-byte slots): 0 x30, 1 expected, 2 dest, 3 op, 4..6 a, 7..9 b, 10 type of a conversion.
884:VALTOK
885 str.x.pre x30 sp -96
886 str.x x0 sp 1
887 str.x x1 sp 2
888 cbz.x x3 E_FEW
889 cmp.x.i x3 3
890 b.eq E_FEW
891 cmp.x.i x3 2
892 b.ne VT_W
893 mov.x x1 x4
894 movz.x x2 0 0
895 movz.x x0 2 0
896 ldr.x x9 sp 1
897 cbz.x x9 VT_RET
898 mov.x x2 x9
899 bl RANGE
900 movz.x x0 3 0
901 b VT_RET
902:VT_W
903 cmp.x.i x5 8
904 b.hi E_LONG
905 mov.x x1 x4
906 bl KW
907 cbnz.x x0 VT_K
908 bl FINDNAME
909 cbz.x x0 E_UNDEF
910 ldr.w w1 x0 2
911 ldr.w w2 x0 3
912 movz.x x0 1 0
913 b VT_RET
914:VT_K
915 sub.x.i x9 x0 1
916 cmp.x.i x9 8
917 b.ls VT_TYPE
918 cmp.x.i x0 74
919 b.eq VT_PAREN
920 cmp.x.i x0 77
921 b.eq E_SUBSET
922 sub.x.i x9 x0 33
923 cmp.x.i x9 17
924 b.hi E_SYNTAX
925 str.x x0 sp 3
926 cmp.x.i x0 49
927 b.hs VT_UN
928; binary op: a, then b; a comparison used as a value is turned into a register at once (flags would not
929; survive the next value)
930 movz.x x0 0 0
931 movz.x x1 255 0
932 bl VAL
933 cmp.x.i x0 4
934 b.ne VB1
935 bl MATREG
936 mov.x x1 x0
937 movz.x x0 1 0
938 movz.x x2 1 0
939:VB1
940 str.x x0 sp 4
941 str.x x1 sp 5
942 str.x x2 sp 6
943 movz.x x0 0 0
944 movz.x x1 255 0
945 bl VAL
946 cmp.x.i x0 4
947 b.ne VB2
948 bl MATREG
949 mov.x x1 x0
950 movz.x x0 1 0
951 movz.x x2 1 0
952:VB2
953 str.x x0 sp 7
954 str.x x1 sp 8
955 str.x x2 sp 9
956; a bare number takes the type of the other value (in a shift too: shl 1 sh)
957 ldr.x x10 sp 4
958 ldr.x x11 sp 7
959 cmp.x.i x10 2
960 b.ne VB3
961 cmp.x.i x11 2
962 b.eq E_BARE
963 ldr.x x1 sp 5
964 ldr.x x2 sp 9
965 bl RANGE
966 str.x x2 sp 6
967 movz.x x0 3 0
968 str.x x0 sp 4
969:VB3
970 cmp.x.i x11 2
971 b.ne VB4
972 ldr.x x1 sp 8
973 ldr.x x2 sp 6
974 bl RANGE
975 str.x x2 sp 9
976 movz.x x0 3 0
977 str.x x0 sp 7
978:VB4
979 ldr.x x0 sp 3
980 cmp.x.i x0 41
981 b.eq VB5
982 cmp.x.i x0 42
983 b.eq VB5
984 ldr.x x1 sp 6
985 ldr.x x2 sp 9
986 cmp.x x1 x2
987 b.ne E_TYPE
988:VB5
989 ldr.x x0 sp 3
990 ldr.x x1 sp 2
991 add.x.i x2 sp 32
992 bl BINOP
993:VT_RET
994 ldr.x.post x30 sp 96
995 ret
996; ( value )
997:VT_PAREN
998 ldr.x x0 sp 1
999 ldr.x x1 sp 2
1000 bl VAL
1001 str.x x0 sp 4
1002 str.x x1 sp 5
1003 str.x x2 sp 6
1004 bl TOK
1005 cmp.x.i x0 1
1006 b.ne E_SYNTAX
1007 cmp.x.i x2 8
1008 b.hi E_SYNTAX
1009 bl KW
1010 cmp.x.i x0 75
1011 b.ne E_SYNTAX
1012 ldr.x x0 sp 4
1013 ldr.x x1 sp 5
1014 ldr.x x2 sp 6
1015 b VT_RET
1016; neg a, not a (a bare number takes the expected type)
1017:VT_UN
1018 ldr.x x0 sp 1
1019 movz.x x1 255 0
1020 bl VAL
1021 ldr.x x9 sp 3
1022 cmp.x.i x9 50
1023 b.ne VU1
1024 cmp.x.i x0 4
1025 b.ne VU1
1026 movz.x x9 1 0
1027 eor.x x1 x1 x9
1028 b VT_RET
1029:VU1
1030 cmp.x.i x0 2
1031 b.eq E_BARE
1032 str.x x2 sp 6
1033 bl MATREG
1034 str.x x0 sp 5
1035 ldr.x x0 sp 2
1036 bl DESTREG
1037 str.x x0 sp 7
1038 ldr.x x9 sp 3
1039 cmp.x.i x9 50
1040 b.eq VU_NOT
1041 ldr.x x9 sp 6
1042 cmp.x.i x9 1
1043 b.eq E_TYPE
1044 cmp.x.i x9 9
1045 b.eq VN64
1046 movz.x x0 0x03e0 0
1047 movk.x x0 0xcb00 1 ; NEG Xd, Xm = SUB Xd, XZR, Xm, C6.2.458
1048 cmp.x.i x9 4
1049 b.ne VN1
1050 movz.x x0 0x03e0 0
1051 movk.x x0 0x4b00 1 ; NEG Wd, Wm (32-bit SUB, C6.2.458): the u32 result comes zero-extended
1052 bl VU_E
1053 b VU_R
1054:VN1
1055 bl VU_E
1056 ldr.x x0 sp 7
1057 ldr.x x1 sp 6
1058 cmp.x.i x1 6
1059 b.hs VN2
1060 bl CANON
1061 b VU_R
1062:VN2
1063 movz.x x2 1 0
1064 bl CHKEXT
1065 b VU_R
1066:VN64
1067 movz.x x0 0x03e0 0
1068 movk.x x0 0xeb00 1 ; NEGS Xd, Xm = SUBS Xd, XZR, Xm, C6.2.465
1069 bl VU_E
1070 movz.x x0 6 0
1071 movz.x x1 1 0
1072 bl TRAPC
1073 b VU_R
1074:VU_NOT
1075 ldr.x x9 sp 6
1076 cmp.x.i x9 1
1077 b.ne VNT1
1078 movz.x x0 0 0
1079 movk.x x0 0xd240 1 ; EOR Xd, Xn, #1 (immediate, N=1 immr=0 imms=0), C6.2.155
1080 ldr.x x1 sp 7
1081 ldr.x x2 sp 5
1082 movz.x x3 0 0
1083 bl E3
1084 b VU_R
1085:VNT1
1086 movz.x x0 0x03e0 0
1087 movk.x x0 0xaa20 1 ; MVN Xd, Xm = ORN Xd, XZR, Xm, C6.2.300
1088 cmp.x.i x9 4
1089 b.ne VNT2
1090 movz.x x0 0x03e0 0
1091 movk.x x0 0x2a20 1 ; MVN Wd, Wm (32-bit ORN, C6.2.300)
1092 bl VU_E
1093 b VU_R
1094:VNT2
1095 bl VU_E
1096 ldr.x x0 sp 7
1097 ldr.x x1 sp 6
1098 cmp.x.i x1 6
1099 b.hs VU_R
1100 bl CANON
1101:VU_R
1102 movz.x x0 1 0
1103 ldr.x x1 sp 7
1104 ldr.x x2 sp 6
1105 b VT_RET
1106:VU_E
1107 ldr.x x1 sp 7
1108 movz.x x2 0 0
1109 ldr.x x3 sp 5
1110 b E3
1111; a type word: a typed number (uint 5) or a conversion of the next value
1112:VT_TYPE
1113 str.x x0 sp 10
1114 bl TOK
1115 cmp.x.i x0 2
1116 b.ne VTT1
1117 ldr.x x2 sp 10
1118 bl RANGE
1119 movz.x x0 3 0
1120 b VT_RET
1121:VTT1
1122 mov.x x3 x0
1123 mov.x x4 x1
1124 mov.x x5 x2
1125 movz.x x0 0 0
1126 movz.x x1 255 0
1127 bl VALTOK
1128 cmp.x.i x0 2
1129 b.eq E_BARE
1130 str.x x2 sp 6
1131 bl MATREG
1132 str.x x0 sp 5
1133 ldr.x x1 sp 6
1134 ldr.x x2 sp 10
1135 cmp.x.i x1 1
1136 b.eq E_SUBSET
1137 cmp.x.i x2 1
1138 b.eq E_SUBSET
1139 adr x9 TWID
1140 ldrb.r w3 x9 x1
1141 ldrb.r w4 x9 x2
1142 cmp.x.i x1 6
1143 b.hs VC_SS
1144 cmp.x.i x2 6
1145 b.hs VC_US
1146 cmp.x x3 x4
1147 b.ls VC_OK
1148 mov.x x5 x4
1149 b VC_LSR
1150:VC_US
1151 cmp.x x3 x4
1152 b.lo VC_OK
1153 sub.x.i x5 x4 1
1154 b VC_LSR
1155:VC_SS
1156 cmp.x.i x2 6
1157 b.hs VC_S2
1158 mov.x x5 x4
1159 cmp.x.i x5 63
1160 b.ls VC_LSR
1161 movz.x x5 63 0
1162 b VC_LSR
1163:VC_S2
1164 cmp.x x3 x4
1165 b.ls VC_OK
1166 ldr.x x0 sp 5
1167 ldr.x x1 sp 10
1168 movz.x x2 5 0
1169 bl CHKEXT
1170 b VC_OK
1171; out of range when any bit at or above x5 is set: LSR Xt, Xa, #x5 = UBFM Xt, Xa, #x5, #63 (C6.2.487);
1172; CBNZ Xt -> trap 5 (C6.2.77)
1173:VC_LSR
1174 bl ALLOC
1175 str.x x0 sp 7
1176 movz.x x1 0xfc00 0
1177 movk.x x1 0xd340 1
1178 orr.x x1 x1 x0
1179 ubfm.x x5 x5 48 47
1180 orr.x x1 x1 x5
1181 ldr.x x2 sp 5
1182 ubfm.x x2 x2 59 58
1183 orr.x x0 x1 x2
1184 bl EMIT
1185 ldr.x x0 sp 7
1186 movz.x x9 0xb500 1 ; CBNZ Xt, C6.2.77
1187 orr.x x0 x0 x9
1188 movz.x x1 5 0
1189 bl TRAPSITE
1190:VC_OK
1191 movz.x x0 1 0
1192 ldr.x x1 sp 5
1193 ldr.x x2 sp 10
1194 b VT_RET
1195; ======================================================================================================
1196; BINOP: x0 op (33..48), x1 destination (255 none), x2 address of two values (kind, number/register,
1197; type) a then b, types already settled. Out: as VAL. Frame: 0 x30, 1 op, 2 rd, 3 values, 4 ra,
1198; 5 rb or immediate, 6 type, 7 1 if b is an immediate, 8 temporary.
1199:BINOP
1200 str.x.pre x30 sp -80
1201 str.x x0 sp 1
1202 str.x x1 sp 2
1203 str.x x2 sp 3
1204 ldr.x x9 x2 2
1205 str.x x9 sp 6
1206 ldr.x x0 x2 0
1207 ldr.x x1 x2 1
1208 ldr.x x2 x2 2
1209 bl MATREG
1210 str.x x0 sp 4
1211 movz.x x9 0 0
1212 str.x x9 sp 7
1213 ldr.x x10 sp 3
1214 ldr.x x0 x10 3
1215 cmp.x.i x0 3
1216 b.ne BO_BREG
1217 ldr.x x1 x10 4
1218 ldr.x x11 sp 1
1219 cmp.x.i x11 41
1220 b.eq BO_IS
1221 cmp.x.i x11 42
1222 b.eq BO_IS
1223 cmp.x.i x11 35
1224 b.lo BO_II
1225 cmp.x.i x11 43
1226 b.lo BO_BREG
1227:BO_II
1228 movz.x x9 4095 0
1229 cmp.x x1 x9
1230 b.hi BO_BREG
1231 b BO_IMM
1232:BO_IS
1233 ldr.x x9 sp 6
1234 adr x12 TWID
1235 ldrb.r w9 x12 x9
1236 cmp.x x1 x9
1237 b.hs BO_BREG
1238:BO_IMM
1239 str.x x1 sp 5
1240 movz.x x9 1 0
1241 str.x x9 sp 7
1242 b BO_OPS
1243:BO_BREG
1244 ldr.x x10 sp 3
1245 ldr.x x0 x10 3
1246 ldr.x x1 x10 4
1247 ldr.x x2 x10 5
1248 bl MATREG
1249 str.x x0 sp 5
1250:BO_OPS
1251 ldr.x x0 sp 1
1252 cmp.x.i x0 43
1253 b.hs BO_CMP
1254 ldr.x x9 sp 6
1255 cmp.x.i x9 1
1256 b.ne BO_NB
1257 sub.x.i x10 x0 38
1258 cmp.x.i x10 2
1259 b.hi E_TYPE
1260:BO_NB
1261 ldr.x x0 sp 2
1262 bl DESTREG
1263 str.x x0 sp 2
1264 ldr.x x0 sp 1
1265 cmp.x.i x0 35
1266 b.lo BO_ADD
1267 b.eq BO_MUL
1268 cmp.x.i x0 38
1269 b.lo BO_DIV
1270 cmp.x.i x0 41
1271 b.lo BO_LOG
1272 b.eq BO_SHL
1273 b BO_SHR
1274; add, sub. u32: 32-bit form (zero-extends); i64: flag-setting form + B.VS trap 1; u8/u16: wrap with
1275; UBFM; i8/i16/i32: exact in 64 bits, then the sign-extension check (trap 1)
1276:BO_ADD
1277 ldr.x x9 sp 1
1278 ldr.x x10 sp 7
1279 cbnz.x x10 BA_I
1280 movz.x x0 0x8b00 1 ; ADD (shifted register) 64-bit, C6.2.6
1281 cmp.x.i x9 33
1282 b.eq BA_S
1283 movz.x x0 0xcb00 1 ; SUB (shifted register) 64-bit, C6.2.458
1284 b BA_S
1285:BA_I
1286 movz.x x0 0x9100 1 ; ADD (immediate) 64-bit, C6.2.5
1287 cmp.x.i x9 33
1288 b.eq BA_S
1289 movz.x x0 0xd100 1 ; SUB (immediate) 64-bit, C6.2.457
1290:BA_S
1291 ldr.x x9 sp 6
1292 cmp.x.i x9 4
1293 b.ne BA2
1294 movz.x x10 0x8000 1 ; sf (bit 31) = 0: the 32-bit form
1295 eor.x x0 x0 x10
1296 bl BO_W3
1297 b BO_RET
1298:BA2
1299 cmp.x.i x9 9
1300 b.ne BA3
1301 movz.x x10 0x2000 1 ; S (bit 29) = 1: ADDS/SUBS, C6.2.10, C6.2.11, C6.2.464, C6.2.465
1302 orr.x x0 x0 x10
1303 bl BO_W3
1304 movz.x x0 6 0
1305 movz.x x1 1 0
1306 bl TRAPC
1307 b BO_RET
1308:BA3
1309 bl BO_W3
1310 bl BO_FIX
1311 b BO_RET
1312; mul. i64: SMULH t (C6.2.379), MUL, CMP t, rd, ASR #63 (C6.2.97), B.NE trap 1
1313:BO_MUL
1314 ldr.x x9 sp 6
1315 cmp.x.i x9 9
1316 b.eq BM64
1317 movz.x x0 0x7c00 0
1318 movk.x x0 0x9b00 1 ; MUL 64-bit = MADD Xd, Xn, Xm, XZR, C6.2.293 / C6.2.275
1319 cmp.x.i x9 4
1320 b.ne BM1
1321 movz.x x10 0x8000 1
1322 eor.x x0 x0 x10
1323 bl BO_W3
1324 b BO_RET
1325:BM1
1326 bl BO_W3
1327 bl BO_FIX
1328 b BO_RET
1329:BM64
1330 bl ALLOC
1331 str.x x0 sp 8
1332 movz.x x0 0x7c00 0
1333 movk.x x0 0x9b40 1 ; SMULH, C6.2.379
1334 ldr.x x1 sp 8
1335 ldr.x x2 sp 4
1336 ldr.x x3 sp 5
1337 bl E3
1338 movz.x x0 0x7c00 0
1339 movk.x x0 0x9b00 1 ; MUL, C6.2.293
1340 bl BO_W3
1341 movz.x x0 0xfc1f 0
1342 movk.x x0 0xeb80 1 ; CMP Xt, Xd, ASR #63 = SUBS XZR, Xt, Xd, ASR #63, C6.2.465
1343 movz.x x1 0 0
1344 ldr.x x2 sp 8
1345 ldr.x x3 sp 2
1346 bl E3
1347 movz.x x0 1 0
1348 movz.x x1 1 0
1349 bl TRAPC
1350 b BO_RET
1351; div, rem (unsigned): CBZ Xb -> trap 2 (C6.2.78), unless b is a number other than 0; UDIV (C6.2.490);
1352; rem: t = a / b; rd = a - t * b (MSUB Xd, Xt, Xb, Xa, C6.2.291)
1353:BO_DIV
1354 ldr.x x9 sp 6
1355 cmp.x.i x9 6
1356 b.hs E_SUBSET
1357 ldr.x x10 sp 3
1358 ldr.x x0 x10 3
1359 cmp.x.i x0 3
1360 b.ne BD1
1361 ldr.x x0 x10 4
1362 cbnz.x x0 BD2
1363:BD1
1364 ldr.x x0 sp 5
1365 movz.x x9 0xb400 1 ; CBZ Xb, C6.2.78
1366 orr.x x0 x0 x9
1367 movz.x x1 2 0
1368 bl TRAPSITE
1369:BD2
1370 ldr.x x9 sp 1
1371 cmp.x.i x9 37
1372 b.eq BD_REM
1373 movz.x x0 0x0800 0
1374 movk.x x0 0x9ac0 1 ; UDIV 64-bit, C6.2.490
1375 bl BO_W3
1376 b BO_RET
1377:BD_REM
1378 bl ALLOC
1379 str.x x0 sp 8
1380 movz.x x0 0x0800 0
1381 movk.x x0 0x9ac0 1 ; UDIV, C6.2.490
1382 ldr.x x1 sp 8
1383 ldr.x x2 sp 4
1384 ldr.x x3 sp 5
1385 bl E3
1386 movz.x x0 0x8000 0
1387 movk.x x0 0x9b00 1 ; MSUB 64-bit, C6.2.291 (Ra at bit 10)
1388 ldr.x x1 sp 4
1389 ubfm.x x1 x1 54 53
1390 orr.x x0 x0 x1
1391 ldr.x x1 sp 2
1392 ldr.x x2 sp 8
1393 ldr.x x3 sp 5
1394 bl E3
1395 b BO_RET
1396; and, or, xor: canonical in, canonical out
1397:BO_LOG
1398 movz.x x0 0x8a00 1 ; AND (shifted register) 64-bit, C6.2.15
1399 ldr.x x9 sp 1
1400 cmp.x.i x9 39
1401 b.lo BL1
1402 movz.x x0 0xaa00 1 ; ORR (shifted register) 64-bit, C6.2.302
1403 b.eq BL1
1404 movz.x x0 0xca00 1 ; EOR (shifted register) 64-bit, C6.2.156
1405:BL1
1406 bl BO_W3
1407 b BO_RET
1408; shl (unsigned): by a number s: LSL #s = UBFM Xd, Xn, #(64-s) mod 64, #(63-s) (C6.2.487), then wrap;
1409; by a register: CMP Xb, #w; B.HS trap 7; LSLV (C6.2.271; 32-bit for u32)
1410:BO_SHL
1411 ldr.x x9 sp 6
1412 cmp.x.i x9 6
1413 b.hs E_SUBSET
1414 ldr.x x10 sp 7
1415 cbnz.x x10 BS_IL
1416 bl BO_SCHK
1417 movz.x x0 0x2000 0
1418 movk.x x0 0x9ac0 1 ; LSLV 64-bit, C6.2.271
1419 ldr.x x9 sp 6
1420 cmp.x.i x9 4
1421 b.ne BS1
1422 movz.x x10 0x8000 1
1423 eor.x x0 x0 x10
1424 bl BO_W3
1425 b BO_RET
1426:BS1
1427 bl BO_W3
1428 bl BO_FIX
1429 b BO_RET
1430:BS_IL
1431 ldr.x x1 sp 5
1432 movz.x x2 64 0
1433 sub.x x2 x2 x1
1434 ubfm.x x2 x2 0 5
1435 movz.x x3 63 0
1436 sub.x x3 x3 x1
1437 movz.x x0 0xd340 1 ; UBFM 64-bit, C6.2.487
1438 ubfm.x x2 x2 48 47
1439 orr.x x0 x0 x2
1440 ubfm.x x3 x3 54 53
1441 orr.x x0 x0 x3
1442 ldr.x x1 sp 4
1443 ubfm.x x1 x1 59 58
1444 orr.x x0 x0 x1
1445 ldr.x x1 sp 2
1446 orr.x x0 x0 x1
1447 bl EMIT
1448 bl BO_FIX
1449 b BO_RET
1450; shr: unsigned LSR, signed ASR. By a number s: UBFM/SBFM Xd, Xn, #s, #63 (C6.2.487, C6.2.355);
1451; by a register: the amount check, then LSRV (C6.2.274) / ASRV (C6.2.21)
1452:BO_SHR
1453 ldr.x x10 sp 7
1454 cbnz.x x10 BR_I
1455 bl BO_SCHK
1456 movz.x x0 0x2400 0
1457 movk.x x0 0x9ac0 1 ; LSRV 64-bit, C6.2.274
1458 ldr.x x9 sp 6
1459 cmp.x.i x9 6
1460 b.lo BR1
1461 movz.x x0 0x2800 0
1462 movk.x x0 0x9ac0 1 ; ASRV 64-bit, C6.2.21
1463:BR1
1464 bl BO_W3
1465 b BO_RET
1466:BR_I
1467 movz.x x0 0xfc00 0
1468 movk.x x0 0xd340 1 ; UBFM Xd, Xn, #s, #63 = LSR, C6.2.487
1469 ldr.x x9 sp 6
1470 cmp.x.i x9 6
1471 b.lo BR2
1472 movz.x x0 0xfc00 0
1473 movk.x x0 0x9340 1 ; SBFM Xd, Xn, #s, #63 = ASR, C6.2.355
1474:BR2
1475 ldr.x x1 sp 5
1476 ubfm.x x1 x1 48 47
1477 orr.x x0 x0 x1
1478 ldr.x x1 sp 4
1479 ubfm.x x1 x1 59 58
1480 orr.x x0 x0 x1
1481 ldr.x x1 sp 2
1482 orr.x x0 x0 x1
1483 bl EMIT
1484 b BO_RET
1485; comparisons: CMP Xa, #imm (C6.2.96) or CMP Xa, Xb (C6.2.97); the result is the flags and a condition
1486:BO_CMP
1487 ldr.x x10 sp 7
1488 cbnz.x x10 BC_I
1489 movz.x x0 0x001f 0
1490 movk.x x0 0xeb00 1 ; CMP (shifted register) = SUBS XZR, Xa, Xb, C6.2.97
1491 ldr.x x1 sp 5
1492 ubfm.x x1 x1 48 47
1493 orr.x x0 x0 x1
1494 b BC_E
1495:BC_I
1496 movz.x x0 0x001f 0
1497 movk.x x0 0xf100 1 ; CMP (immediate) = SUBS XZR, Xa, #imm, C6.2.96
1498 ldr.x x1 sp 5
1499 ubfm.x x1 x1 54 53
1500 orr.x x0 x0 x1
1501:BC_E
1502 ldr.x x1 sp 4
1503 ubfm.x x1 x1 59 58
1504 orr.x x0 x0 x1
1505 bl EMIT
1506 ldr.x x9 sp 1
1507 sub.x.i x9 x9 43
1508 add.x x9 x9 x9
1509 ldr.x x10 sp 6
1510 cmp.x.i x10 6
1511 b.lo BC1
1512 add.x.i x9 x9 1
1513:BC1
1514 adr x10 CONDS
1515 ldrb.r w1 x10 x9
1516 movz.x x0 4 0
1517 movz.x x2 1 0
1518 b BO_RET2
1519:BO_RET
1520 movz.x x0 1 0
1521 ldr.x x1 sp 2
1522 ldr.x x2 sp 6
1523:BO_RET2
1524 ldr.x.post x30 sp 80
1525 ret
1526; BO_W3: x0 fixed part; emit it | rd | ra << 5 | (imm12 << 10, or rb << 16), fields from the BINOP frame
1527:BO_W3
1528 ldr.x x1 sp 2
1529 orr.x x0 x0 x1
1530 ldr.x x1 sp 4
1531 ubfm.x x1 x1 59 58
1532 orr.x x0 x0 x1
1533 ldr.x x1 sp 5
1534 ldr.x x2 sp 7
1535 cbnz.x x2 BW_I
1536 ubfm.x x1 x1 48 47
1537 orr.x x0 x0 x1
1538 b EMIT
1539:BW_I
1540 ubfm.x x1 x1 54 53
1541 orr.x x0 x0 x1
1542 b EMIT
1543; BO_FIX: after a 64-bit op on rd: u8/u16/u32 wrap (CANON), i8/i16/i32 overflow check (trap 1)
1544:BO_FIX
1545 ldr.x x1 sp 6
1546 ldr.x x0 sp 2
1547 cmp.x.i x1 6
1548 b.lo CANON
1549 cmp.x.i x1 9
1550 b.eq BF_X
1551 movz.x x2 1 0
1552 b CHKEXT
1553:BF_X
1554 ret
1555; BO_SCHK: shift amount in a register must be below the width: CMP Xb, #w (C6.2.96); B.HS trap 7
1556:BO_SCHK
1557 ldr.x x1 sp 6
1558 adr x9 TWID
1559 ldrb.r w1 x9 x1
1560 ldr.x x2 sp 5
1561 movz.x x0 0x001f 0
1562 movk.x x0 0xf100 1 ; CMP Xb, #w, C6.2.96
1563 ubfm.x x1 x1 54 53
1564 orr.x x0 x0 x1
1565 ubfm.x x2 x2 59 58
1566 orr.x x0 x0 x2
1567 str.x.pre x30 sp -16
1568 bl EMIT
1569 movz.x x0 2 0
1570 movz.x x1 7 0
1571 bl TRAPC
1572 ldr.x.post x30 sp 16
1573 ret
1574; ======================================================================================================
1575; COND: read a condition (a bool value); emit a branch taken when it is false; x0 = that branch's address
1576:COND
1577 str.x.pre x30 sp -16
1578 movz.x x0 1 0
1579 movz.x x1 255 0
1580 bl VAL
1581 cmp.x.i x2 1
1582 b.ne E_TYPE
1583 cmp.x.i x0 4
1584 b.ne CO1
1585 movz.x x9 1 0
1586 eor.x x1 x1 x9
1587 movz.x x0 0x5400 1 ; B.cond with the opposite condition, C6.2.34
1588 orr.x x0 x0 x1
1589 b CO2
1590:CO1
1591 bl MATREG
1592 movz.x x9 0xb400 1 ; CBZ Xr, C6.2.78
1593 orr.x x0 x0 x9
1594:CO2
1595 mov.x x10 x20
1596 bl EMIT
1597 mov.x x0 x10
1598 ldr.x.post x30 sp 16
1599 ret
1600; MATREG: x0 kind, x1 number/register/condition, x2 type -> x0 a register holding the value
1601:MATREG
1602 cmp.x.i x0 1
1603 b.ne MR1
1604 mov.x x0 x1
1605 ret
1606:MR1
1607 str.x.pre x30 sp -32
1608 str.x x0 sp 1
1609 str.x x1 sp 2
1610 str.x x2 sp 3
1611 bl ALLOC
1612 mov.x x3 x0
1613 ldr.x x0 sp 1
1614 ldr.x x1 sp 2
1615 ldr.x x2 sp 3
1616 str.x x3 sp 1
1617 bl FORCE
1618 ldr.x x0 sp 1
1619 ldr.x.post x30 sp 32
1620 ret
1621; FORCE: x0 kind, x1 number/register/condition, x2 type, x3 register: put the value in that register
1622:FORCE
1623 str.x.pre x30 sp -16
1624 cmp.x.i x0 1
1625 b.eq FO_R
1626 cmp.x.i x0 3
1627 b.eq FO_C
1628 cmp.x.i x0 4
1629 b.ne E_BARE
1630 mov.x x0 x3
1631 bl CSET
1632 b FO_X
1633:FO_R
1634 cmp.x x1 x3
1635 b.eq FO_X
1636 movz.x x0 0x03e0 0
1637 movk.x x0 0xaa00 1 ; MOV Xd, Xm = ORR Xd, XZR, Xm, C6.2.282
1638 orr.x x0 x0 x3
1639 ubfm.x x1 x1 48 47
1640 orr.x x0 x0 x1
1641 bl EMIT
1642 b FO_X
1643:FO_C
1644 mov.x x0 x3
1645 bl MATCONST
1646:FO_X
1647 ldr.x.post x30 sp 16
1648 ret
1649; CSET Xd, cond = CSINC Xd, XZR, XZR, opposite cond (C6.2.141). x0 register, x1 condition
1650:CSET
1651 movz.x x9 0x07e0 0
1652 movk.x x9 0x9a9f 1 ; CSINC 64-bit, Rm = Rn = 31, C6.2.141
1653 orr.x x9 x9 x0
1654 movz.x x0 1 0
1655 eor.x x1 x1 x0
1656 ubfm.x x1 x1 52 51
1657 orr.x x0 x9 x1
1658 b EMIT
1659; MATCONST: x0 register, x1 64-bit value: MOVZ (C6.2.285) or, for a negative value, MOVN (C6.2.284) with
1660; the first halfword that differs from the fill, then MOVK (C6.2.283) for each other such halfword
1661:MATCONST
1662 str.x.pre x30 sp -16
1663 mov.x x3 x0
1664 mov.x x4 x1
1665 movz.x x5 0 0
1666 movz.x x6 0 0
1667 movz.x x7 0xd280 1 ; MOVZ 64-bit, C6.2.285
1668 movz.x x8 0 0
1669 cmp.x.i x4 0
1670 b.ge MC2
1671 movz.x x6 0xffff 0
1672 movz.x x7 0x9280 1 ; MOVN 64-bit, C6.2.284
1673:MC2
1674 ubfm.x x2 x5 60 59
1675 lsrv.x x1 x4 x2
1676 ubfm.x x1 x1 0 15
1677 cmp.x x1 x6
1678 b.eq MC4
1679 movz.x x0 0xf280 1 ; MOVK 64-bit, C6.2.283
1680 cbnz.x x8 MC3
1681 eor.x x1 x1 x6
1682 mov.x x0 x7
1683 movz.x x8 1 0
1684:MC3
1685 ubfm.x x1 x1 59 58
1686 orr.x x0 x0 x1
1687 ubfm.x x2 x5 43 42
1688 orr.x x0 x0 x2
1689 orr.x x0 x0 x3
1690 bl EMIT
1691:MC4
1692 add.x.i x5 x5 1
1693 cmp.x.i x5 4
1694 b.lo MC2
1695 cbnz.x x8 MC5
1696 orr.x x0 x7 x3
1697 bl EMIT
1698:MC5
1699 ldr.x.post x30 sp 16
1700 ret
1701; CANON: x0 register, x1 type: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355)
1702:CANON
1703 cmp.x.i x1 2
1704 b.lo CN_X
1705 cmp.x.i x1 5
1706 b.lo CN_U
1707 cmp.x.i x1 6
1708 b.lo CN_X
1709 cmp.x.i x1 9
1710 b.lo CN_S
1711:CN_X
1712 ret
1713:CN_U
1714 movz.x x9 0xd340 1 ; UBFM 64-bit, C6.2.487
1715 b CN_GO
1716:CN_S
1717 movz.x x9 0x9340 1 ; SBFM 64-bit, C6.2.355
1718:CN_GO
1719 adr x10 TWID
1720 ldrb.r w10 x10 x1
1721 sub.x.i x10 x10 1
1722 ubfm.x x10 x10 54 53
1723 orr.x x9 x9 x10
1724 orr.x x9 x9 x0
1725 ubfm.x x0 x0 59 58
1726 orr.x x0 x9 x0
1727 b EMIT
1728; CHKEXT: x0 register, x1 type (i8 i16 i32), x2 trap code: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended,
1729; option 100/101/110, C6.2.463), then B.NE trap
1730:CHKEXT
1731 sub.x.i x3 x1 2
1732 ubfm.x x3 x3 51 50
1733 movz.x x9 0x001f 0
1734 movk.x x9 0xeb20 1 ; SUBS (extended register) 64-bit, Rd 31 = CMP, C6.2.463
1735 orr.x x3 x3 x9
1736 ubfm.x x9 x0 48 47
1737 orr.x x3 x3 x9
1738 ubfm.x x9 x0 59 58
1739 orr.x x0 x3 x9
1740 str.x.pre x30 sp -16
1741 bl EMIT
1742 movz.x x0 1 0
1743 mov.x x1 x2
1744 bl TRAPC
1745 ldr.x.post x30 sp 16
1746 ret
1747; RANGE: x1 number, x2 type: error 8 unless the number is a value of that type
1748:RANGE
1749 adr x9 TWID
1750 ldrb.r w9 x9 x2
1751 cmp.x.i x9 64
1752 b.eq RG_64
1753 movz.x x10 1 0
1754 lslv.x x10 x10 x9
1755 cmp.x.i x2 6
1756 b.hs RG_S
1757 cmp.x x1 x10
1758 b.hs E_RANGE
1759 ret
1760:RG_S
1761 ubfm.x x10 x10 1 63
1762 add.x x11 x1 x10
1763 add.x x10 x10 x10
1764 cmp.x x11 x10
1765 b.hs E_RANGE
1766 ret
1767:RG_64
1768 cmp.x.i x2 9
1769 b.eq RG_OK
1770 cmp.x.i x1 0
1771 b.lt E_RANGE
1772:RG_OK
1773 ret
1774; ======================================================================================================
1775; TOK: next word. x0 kind (0 end of line, 1 word, 2 number, 3 end of input), x1 packed word (first 8
1776; characters, first in the low byte) or number, x2 length. Clobbers x0..x7.
1777:TOK
1778 ldrb w0 x19 0
1779 cmp.w.i w0 32
1780 b.eq TK_SKIP
1781 cmp.w.i w0 9
1782 b.eq TK_SKIP
1783 cmp.w.i w0 13
1784 b.eq TK_SKIP
1785 cbz.w w0 TK_EOF
1786 cmp.w.i w0 10
1787 b.ne TK_WORD
1788 add.x.i x19 x19 1
1789 add.x.i x22 x22 1
1790 movz.x x0 0 0
1791 ret
1792:TK_SKIP
1793 add.x.i x19 x19 1
1794 b TOK
1795:TK_EOF
1796 movz.x x0 3 0
1797 ret
1798:TK_WORD
1799 movz.x x1 0 0
1800 movz.x x2 0 0
1801 movz.x x3 0 0
1802:TK_CH
1803 ldrb w0 x19 0
1804 cmp.w.i w0 32
1805 b.ls TK_END
1806 cmp.x.i x2 8
1807 b.hs TK_LONG
1808 lslv.x x4 x0 x3
1809 orr.x x1 x1 x4
1810 add.x.i x3 x3 8
1811:TK_LONG
1812 add.x.i x2 x2 1
1813 add.x.i x19 x19 1
1814 b TK_CH
1815:TK_END
1816 ubfm.x x4 x1 0 7
1817 cmp.x.i x4 45
1818 b.eq TK_NUM
1819 sub.x.i x4 x4 48
1820 cmp.x.i x4 9
1821 b.ls TK_NUM
1822 movz.x x0 1 0
1823 ret
1824; a number: [-]decimal, at most 19 digits, inside the signed 64-bit range
1825:TK_NUM
1826 sub.x x5 x19 x2
1827 movz.x x6 0 0
1828 ldrb w0 x5 0
1829 cmp.w.i w0 45
1830 b.ne TK_N1
1831 movz.x x6 1 0
1832 add.x.i x5 x5 1
1833:TK_N1
1834 sub.x x0 x19 x5
1835 cbz.x x0 E_NUM
1836 cmp.x.i x0 19
1837 b.hi E_NUM
1838 movz.x x1 0 0
1839 movz.x x7 10 0
1840:TK_N2
1841 cmp.x x5 x19
1842 b.hs TK_N3
1843 ldrb w0 x5 0
1844 sub.x.i x0 x0 48
1845 cmp.x.i x0 9
1846 b.hi E_NUM
1847 mul.x x1 x1 x7
1848 add.x x1 x1 x0
1849 add.x.i x5 x5 1
1850 b TK_N2
1851:TK_N3
1852 movz.x x7 0x8000 3
1853 cbnz.x x6 TK_NEG
1854 cmp.x x1 x7
1855 b.hs E_RANGE
1856 movz.x x0 2 0
1857 ret
1858:TK_NEG
1859 cmp.x x1 x7
1860 b.hi E_RANGE
1861 sub.x x1 xzr x1
1862 movz.x x0 2 0
1863 ret
1864; KW: x1 packed word -> x0 keyword code (0 none). Clobbers x9..x11.
1865:KW
1866 adr x9 KWTAB
1867:KW1
1868 ldr.w w0 x9 2
1869 cbz.w w0 KW2
1870 ldr.x x10 x9 0
1871 cmp.x x10 x1
1872 b.eq KW2
1873 add.x.i x9 x9 16
1874 b KW1
1875:KW2
1876 ret
1877; TYPEWORD: read a type name -> x0 type 1..9
1878:TYPEWORD
1879 str.x.pre x30 sp -16
1880 bl TOK
1881 cbz.x x0 E_FEW
1882 cmp.x.i x0 1
1883 b.ne E_SYNTAX
1884 cmp.x.i x2 8
1885 b.hi E_SYNTAX
1886 bl KW
1887 cmp.x.i x0 76
1888 b.eq E_SUBSET
1889 sub.x.i x9 x0 1
1890 cmp.x.i x9 8
1891 b.hi E_SYNTAX
1892 ldr.x.post x30 sp 16
1893 ret
1894; EOL: the line must end here
1895:EOL
1896 str.x.pre x30 sp -16
1897 bl TOK
1898 cbz.x x0 EOL1
1899 cmp.x.i x0 3
1900 b.ne E_EXTRA
1901:EOL1
1902 ldr.x.post x30 sp 16
1903 ret
1904; FINDNAME: x1 packed name -> x0 its entry (0 none). Clobbers x9..x11.
1905:FINDNAME
1906 movz.x x9 0x70 1
1907 movz.x x10 0 0
1908:FD1
1909 cmp.x x10 x23
1910 b.hs FD0
1911 ldr.x x11 x9 0
1912 cmp.x x11 x1
1913 b.eq FDF
1914 add.x.i x9 x9 16
1915 add.x.i x10 x10 1
1916 b FD1
1917:FD0
1918 movz.x x0 0 0
1919 ret
1920:FDF
1921 mov.x x0 x9
1922 ret
1923; ADDNAME: x1 packed name, x2 register, x3 type. Clobbers x9, x10.
1924:ADDNAME
1925 cmp.x.i x23 64
1926 b.hs E_FULL
1927 movz.x x9 0x70 1
1928 ubfm.x x10 x23 60 59
1929 add.x x9 x9 x10
1930 str.x x1 x9 0
1931 str.w w2 x9 2
1932 str.w w3 x9 3
1933 add.x.i x23 x23 1
1934 ret
1935; PUSHB: x0 branch to patch, x1 kind (1 if, 2 else, 3 while, 4 for), x2 head, x3 loop register,
1936; x4 its type, x5 names and x6 pool slots to restore at end
1937:PUSHB
1938 movz.x x9 0x72 1
1939 cmp.x x25 x9
1940 b.hs E_FULL
1941 str.x x1 x25 0
1942 str.x x0 x25 1
1943 str.x x2 x25 2
1944 str.x x3 x25 3
1945 str.x x4 x25 4
1946 str.x x5 x25 5
1947 str.x x6 x25 6
1948 add.x.i x25 x25 64
1949 ret
1950; ALLOC: -> x0 the next free register of the pool. Clobbers x9.
1951:ALLOC
1952 add.x x0 x29 x24
1953 adr x9 POOLEND
1954 cmp.x x0 x9
1955 b.hs E_REGS
1956 ldrb w0 x0 0
1957 add.x.i x24 x24 1
1958 ret
1959; DESTREG: x0 destination register, or 255 for a new temporary
1960:DESTREG
1961 cmp.x.i x0 255
1962 b.eq ALLOC
1963 ret
1964; EMIT: x0 word -> output. Clobbers x9.
1965:EMIT
1966 movz.x x9 0x70 1
1967 cmp.x x20 x9
1968 b.hs E_FULL
1969 str.w.post w0 x20 4
1970 ret
1971; E3: emit x0 | x1 | x2 << 5 | x3 << 16. Clobbers x0..x3, x9.
1972:E3
1973 orr.x x0 x0 x1
1974 ubfm.x x2 x2 59 58
1975 orr.x x0 x0 x2
1976 ubfm.x x3 x3 48 47
1977 orr.x x0 x0 x3
1978 b EMIT
1979; TRAPC: x0 condition, x1 trap code: B.cond (C6.2.34) to the trap stub, distance filled at the end
1980:TRAPC
1981 movz.x x9 0x5400 1
1982 orr.x x0 x0 x9
1983; TRAPSITE: x0 branch word, x1 trap code: note the place, emit the word
1984:TRAPSITE
1985 movz.x x9 0x73 1
1986 cmp.x x26 x9
1987 b.hs E_FULL
1988 str.w w20 x26 0
1989 str.w w1 x26 1
1990 add.x.i x26 x26 8
1991 b EMIT
1992; PATCH19: x0 address of a B.cond/CBZ/CBNZ, x1 target: the word distance into bits 5..23
1993:PATCH19
1994 sub.x x2 x1 x0
1995 ubfm.x x2 x2 2 20
1996 ubfm.x x2 x2 59 58
1997 ldr.w w1 x0 0
1998 orr.x x1 x1 x2
1999 str.w w1 x0 0
2000 ret
2001; PATCH26: x0 address of a B, x1 target: the word distance into bits 0..25
2002:PATCH26
2003 sub.x x2 x1 x0
2004 ubfm.x x2 x2 2 27
2005 ldr.w w1 x0 0
2006 orr.x x1 x1 x2
2007 str.w w1 x0 0
2008 ret
2009; BACK: x0 earlier address: emit B to it (C6.2.35)
2010:BACK
2011 sub.x x2 x0 x20
2012 ubfm.x x2 x2 2 27
2013 movz.x x0 0x1400 1 ; B, C6.2.35
2014 orr.x x0 x0 x2
2015 b EMIT
2016; ======================================================================================================
2017; errors
2018:E_READ
2019 movz.x x0 1 0
2020 b FAIL
2021:E_WRITE
2022 movz.x x0 2 0
2023 b FAIL
2024:E_UNDEF
2025 movz.x x0 3 0
2026 b FAIL
2027:E_FEW
2028 movz.x x0 4 0
2029 b FAIL
2030:E_EXTRA
2031 movz.x x0 5 0
2032 b FAIL
2033:E_NUM
2034 movz.x x0 6 0
2035 b FAIL
2036:E_TYPE
2037 movz.x x0 7 0
2038 b FAIL
2039:E_RANGE
2040 movz.x x0 8 0
2041 b FAIL
2042:E_SUBSET
2043 movz.x x0 9 0
2044 b FAIL
2045:E_TWICE
2046 movz.x x0 10 0
2047 b FAIL
2048:E_BARE
2049 movz.x x0 11 0
2050 b FAIL
2051:E_REGS
2052 movz.x x0 12 0
2053 b FAIL
2054:E_LONG
2055 movz.x x0 13 0
2056 b FAIL
2057:E_FULL
2058 movz.x x0 14 0
2059 b FAIL
2060:E_BLOCK
2061 movz.x x0 15 0
2062 b FAIL
2063:E_SYNTAX
2064 movz.x x0 16 0
2065; FAIL: x0 code: "om3: line N: error E" and a newline on stderr (fd 2), exit E
2066:FAIL
2067 mov.x x12 x0
2068 movz.x x9 0x73 1
2069 adr x10 MSG1
2070 bl COPYZ
2071 mov.x x0 x22
2072 bl PUTDEC
2073 adr x10 MSG2
2074 bl COPYZ
2075 mov.x x0 x12
2076 bl PUTDEC
2077 movz.x x0 10 0
2078 strb w0 x9 0
2079 add.x.i x9 x9 1
2080 movz.x x0 2 0
2081 movz.x x1 0x73 1
2082 sub.x x2 x9 x1
2083 movz.x x8 64 0
2084 svc 0
2085 mov.x x0 x12
2086 movz.x x8 93 0
2087 svc 0
2088; COPYZ: copy the NUL-ended text at x10 to x9 (x9 moves on)
2089:COPYZ
2090 ldrb w11 x10 0
2091 cbz.w w11 CZ1
2092 strb w11 x9 0
2093 add.x.i x9 x9 1
2094 add.x.i x10 x10 1
2095 b COPYZ
2096:CZ1
2097 ret
2098; PUTDEC: x0 number: its decimal digits at x9 (x9 moves on)
2099:PUTDEC
2100 movz.x x1 10 0
2101 add.x.i x2 x9 40
2102 mov.x x3 x2
2103:PD1
2104 udiv.x x4 x0 x1
2105 msub.x x5 x4 x1 x0
2106 add.x.i x5 x5 48
2107 sub.x.i x3 x3 1
2108 strb w5 x3 0
2109 mov.x x0 x4
2110 cbnz.x x0 PD1
2111:PD2
2112 ldrb w5 x3 0
2113 strb w5 x9 0
2114 add.x.i x9 x9 1
2115 add.x.i x3 x3 1
2116 cmp.x x3 x2
2117 b.lo PD2
2118 ret