; memory map M[.]
; code 0..500
; global 1000..1100
; symtab 2000..2999

; global
; 1000 CH
; 1001 CS
; 1002 CP

1 call boot2
2 call testboot2
3 end

; isNum c
20 fun 1
21 get 1
22 lit 48
23 ge
24 get 1
25 lit 57
26 le
27 and
28 ret 2

;; isSpace c
29 fun 1
30 get 1
31 lit 32
32 eq
33 get 1
34 lit 10
35 eq
36 or
37 get 1
38 lit 0
39 lt
40 or
41 ret 2

;; readc {c}
60 fun 2
61 sys 3
62 put 1
63 get 1
64 st 1000
65 get 1
66 ret 2

;; readi c { n pos}
70 fun 3
71 get 3
72 lit 48
73 sub
74 put 2
75 get 2
76 put 1
77 jmp x
loop:
78 get 2
79 lit 10
80 mul
81 ld 1000
82 add
83 lit 48
84 sub
85 put 2
x: 
86 call readc
87 call isspace
88 not
89 jt loop
90 get 1
91 jf y
92 get 2
93 ret 4
y:
94 lit 0
95 get 2
96 sub
97 ret 4

;; boot {op arg i}
100 fun 4
101 call readc
102 call readi
103 put 3
104 jmp x
loop:
105 call readc
106 call readi
107 put 2
108 get 3
109 sys 1
110 lit 32
111 sys 2
112 get 2
113 sys 1
114 lit 10
115 sys 2
116 call readc
117 call readi
118 put 3
x:
119 get 3
120 lit 0
121 ne
122 jt loop
123 ret 4

; test boot 
; with some s-object

; 32 17
; 23 0
; 38 1
; 0

; 130 boot2 {op arg i}
130 fun 4
131 lit 301000
132 st CS
133 lit 159
134 put 1
135 call readc
136 call readi
137 put 3
138 jmp x
loop:
139 call readc
140 call readi
141 put 2
142 ld CS
143 get 1
144 get 2
145 lit 8
146 shl
147 get 3
148 or
149 stx
150 inc 1
151 call readc
152 call readi
153 put 3
x:
154 get 3
155 lit 0
156 ne
157 jt loop
158 ret 4

; test boot2 with simple
; program

; testboot2
159 fun 1
160 lit 1
161 lit 2
162 add
163 sys 1
164 ret 1
