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 / helix / rung1 / hexB1.b1

246 lines · 6477 bytes Raw Blame History
1; hexB1.b1 -- Rung B1 of Strand B (labelled byte/word assembler, self-hosting)
27f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 02 00 b7 00 01 00 00 00 78 00 50 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 38 00 01 00 00 00 00 00 00 00 ; ELF-64 file header (64B)
301 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 50 00 00 00 00 00 00 00 50 00 00 00 00 00 ; PT_LOAD header part 1
4$ ; p_filesz (auto) = 948
500 00 40 00 00 00 00 00 00 10 00 00 00 00 00 00 ; p_memsz & p_align
6=d10083ff ; sub sp, sp, #32
7=910003fc ; mov x28, sp (name buf)
8=d2a00c13 ; x19 = 0x600000 (in_base)
9=d2800014 ; x20 = 0 (in_len)
10=d2a00e17 ; x23 = 0x700000 (out_base)
11=d2a00b19 ; x25 = 0x580000 (lbl_base)
12=d280001a ; x26 = 0 (lbl_cnt)
13=d280001b ; x27 = 0 (total_len)
14:rd_loop
15=d2a00202 ; x2 = 0x100000 (1 MiB)
16=cb140042 ; x2 = avail
17=b4000002 @err_cap ; if avail==0 -> err 9
18=d2800000 ; fd 0
19=8b140261 ; x1 = in_base + in_len
20=d28007e8 ; SYS_read
21=d4000001 ; svc #0
22=f100001f ; cmp x0, #0
23=54000000 @rd_done ; eof
24=5400000b @err_rd ; read err
25=8b000294 ; in_len += n
26=14000000 ^rd_loop ; loop read
27:rd_done
28=d2800015 ; pass = 0
29:pass_start
30=d2800016 ; cursor = 0
31=d2800018 ; out_pos = 0
32:tok_loop
33=eb1402df ; cmp cursor, in_len
34=54000002 @pass_done ; if cursor >= in_len
35=38766a60 ; w0 = in[cursor]
36=910006d6 ; cursor++
37=7100801f ; cmp ' '
38=54000000 @tok_loop ; skip space
39=7100281f ; cmp LF
40=54000000 @tok_loop ; skip LF
41=7100241f ; cmp TAB
42=54000000 @tok_loop ; skip TAB
43=7100341f ; cmp CR
44=54000000 @tok_loop ; skip CR
45=7100ec1f ; cmp ';'
46=54000001 @not_cmt ; not comment
47:cmt_loop
48=eb1402df ; cmp cursor, in_len
49=54000002 @pass_done ; eof in cmt
50=38766a60 ; w0 = in[cursor]
51=910006d6 ; cursor++
52=7100281f ; cmp LF
53=54000001 @cmt_loop ; until LF
54=14000000 ^tok_loop ; done cmt
55:not_cmt
56=7100e81f ; cmp ':'
57=54000001 @not_def ; not :
58=94000000 ^rd_name ; read label name into [x28]
59=b5000015 @tok_loop ; pass 1 skips def
60=d37beb41 ; x1 = lbl_cnt * 32
61=8b010321 ; x1 = entry addr
62=f9400382 ; name[0..7]
63=f9400783 ; name[8..15]
64=f9000022 ; store name[0..7]
65=f9000423 ; store name[8..15]
66=f9000838 ; store offset = out_pos
67=9100075a ; lbl_cnt++
68=14000000 ^tok_loop ; next
69:not_def
70=7100f41f ; cmp '='
71=54000001 @not_word ; not =
72=d2800009 ; w9 = acc
73=d280010a ; x10 = 8 digits
74:w_loop
75=eb1402df ; cmp cursor, in_len
76=54000002 @err_hex ; truncated word
77=38766a60 ; w0 = ch
78=910006d6 ; cursor++
79=94000000 ^hex_val ; x0 = 0..15
80=531c6d29 ; w9 <<= 4
81=2a000129 ; w9 |= w0
82=f100054a ; x10--
83=54000001 @w_loop ; more digits
84=b4000015 @w_skip ; pass 0 no write
85=b8386ae9 ; out[out_pos] = w9
86:w_skip
87=91001318 ; out_pos += 4
88=14000000 ^tok_loop ; next
89:not_word
90=7101001f ; cmp '@'
91=54000001 @not_b19 ; not @
92=94000000 ^rd_name ; read label
93=b4000015 @tok_loop ; pass 0 skip
94=94000000 ^find_lbl ; x0 = target off
95=d1001301 ; x1 = out_pos - 4
96=cb010000 ; x0 = target - pc
97=9342fc00 ; x0 >>= 2
98=d29fffe2 ; x2 = 0xffff
99=f2a000e2 ; x2 = 0x7ffff
100=8a020000 ; x0 &= 0x7ffff
101=d37be800 ; x0 <<= 5
102=b8616ae3 ; w3 = prev word
103=2a000063 ; w3 |= w0
104=b8216ae3 ; store patched word
105=14000000 ^tok_loop ; next
106:not_b19
107=7101781f ; cmp '^'
108=54000001 @not_b26 ; not ^
109=94000000 ^rd_name ; read label
110=b4000015 @tok_loop ; pass 0 skip
111=94000000 ^find_lbl ; x0 = target off
112=d1001301 ; x1 = out_pos - 4
113=cb010000 ; x0 = target - pc
114=9342fc00 ; x0 >>= 2
115=d29fffe2 ; x2 = 0xffff
116=f2a07fe2 ; x2 = 0x3ffffff
117=8a020000 ; x0 &= 0x3ffffff
118=b8616ae3 ; w3 = prev word
119=2a000063 ; w3 |= w0
120=b8216ae3 ; store patched word
121=14000000 ^tok_loop ; next
122:not_b26
123=7100901f ; cmp '$'
124=54000001 @do_byte ; not $
125=b4000015 @sz_skip ; pass 0 skip
126=f8386afb ; out[out_pos] = total_len
127:sz_skip
128=91002318 ; out_pos += 8
129=14000000 ^tok_loop ; next
130:do_byte
131=94000000 ^hex_val ; first nibble
132=531c6c09 ; w9 = hi << 4
133=eb1402df ; cmp cursor, in_len
134=54000002 @err_hex ; odd nibble
135=38766a60 ; w0 = second ch
136=910006d6 ; cursor++
137=94000000 ^hex_val ; second nibble
138=2a000129 ; w9 |= lo
139=b4000015 @b_skip ; pass 0 skip
140=38386ae9 ; out[out_pos] = w9
141:b_skip
142=91000718 ; out_pos += 1
143=14000000 ^tok_loop ; next
144:pass_done
145=b5000015 @write_out ; if pass==1 -> write
146=aa1803fb ; total_len = out_pos
147=d2800035 ; pass = 1
148=14000000 ^pass_start ; start pass 1
149:write_out
150=d2800009 ; written = 0
151:wr_loop
152=eb18013f ; cmp written, out_pos
153=54000002 @ok_exit ; done write
154=d2800020 ; fd 1
155=8b0902e1 ; ptr = out_base + written
156=cb090302 ; rem = out_pos - written
157=d2800808 ; SYS_write
158=d4000001 ; svc #0
159=f100001f ; cmp x0, #0
160=5400000d @err_wr ; write err
161=8b000129 ; written += n
162=14000000 ^wr_loop ; loop write
163:ok_exit
164=d2800000 ; exit 0
165=14000000 ^do_exit ; exit
166:hex_val
167=7100c001 ; w1 = w0 - '0'
168=7100283f ; cmp w1, #10
169=54000003 @hv_ok ; 0-9
170=71018401 ; w1 = w0 - 'a'
171=7100183f ; cmp w1, #6
172=54000003 @hv_add10 ; a-f
173=71010401 ; w1 = w0 - 'A'
174=7100183f ; cmp w1, #6
175=54000003 @hv_add10 ; A-F
176=d28000a0 ; bad hex -> exit 5
177=14000000 ^do_exit ; exit
178:hv_add10
179=11002821 ; w1 += 10
180:hv_ok
181=2a0103e0 ; w0 = w1
182=d65f03c0 ; ret
183:rd_name
184=f900039f ; zero name[0..7]
185=f900079f ; zero name[8..15]
186=d2800001 ; i = 0
187:rn_loop
188=eb1402df ; cmp cursor, in_len
189=54000002 @rn_done ; eof
190=38766a60 ; w0 = ch
191=7100801f ; cmp ' '
192=54000000 @rn_done ; ws
193=7100281f ; cmp LF
194=54000000 @rn_done ; ws
195=7100241f ; cmp TAB
196=54000000 @rn_done ; ws
197=7100341f ; cmp CR
198=54000000 @rn_done ; ws
199=7100ec1f ; cmp ';'
200=54000000 @rn_done ; cmt
201=f100403f ; cmp i, #16
202=54000002 @err_hex ; name > 16
203=38216b80 ; name[i] = w0
204=91000421 ; i++
205=910006d6 ; cursor++
206=14000000 ^rn_loop ; loop
207:rn_done
208=b4000001 @err_hex ; empty name
209=d65f03c0 ; ret
210:find_lbl
211=f9400382 ; want0
212=f9400783 ; want1
213=d2800001 ; i = 0
214:fl_loop
215=eb1a003f ; cmp i, lbl_cnt
216=54000002 @err_lbl ; not found
217=d37be824 ; x4 = i * 32
218=8b040324 ; x4 = entry
219=f9400085 ; got0
220=eb0200bf ; cmp got0, want0
221=54000001 @fl_next ; miss0
222=f9400485 ; got1
223=eb0300bf ; cmp got1, want1
224=54000001 @fl_next ; miss1
225=f9400880 ; x0 = offset
226=d65f03c0 ; ret
227:fl_next
228=91000421 ; i++
229=14000000 ^fl_loop ; loop
230:err_hex
231=d28000c0 ; exit 6
232=14000000 ^do_exit ; exit
233:err_lbl
234=d28000e0 ; exit 7
235=14000000 ^do_exit ; exit
236:err_wr
237=d2800100 ; exit 8
238=14000000 ^do_exit ; exit
239:err_rd
240=d2800120 ; exit 9
241=14000000 ^do_exit ; exit
242:err_cap
243=d2800140 ; exit 10
244:do_exit
245=d2800ba8 ; SYS_exit
246=d4000001 ; svc #0