git @ Cat's Eye Technologies SixtyPical / da44e1b
Many, many define main routine, define foo routine, etc. Chris Pressey 3 years ago
1 changed file(s) with 238 addition(s) and 238 deletion(s). Raw diff Collapse all Expand all
1414
1515 Routines must declare their inputs, outputs, and memory locations they trash.
1616
17 | routine up
17 | define up routine
1818 | inputs a
1919 | outputs a
2020 | trashes c, z, v, n
2626
2727 Routines may not declare a memory location to be both an output and trashed.
2828
29 | routine main
29 | define main routine
3030 | outputs a
3131 | trashes a
3232 | {
3636
3737 If a routine declares it outputs a location, that location should be initialized.
3838
39 | routine main
39 | define main routine
4040 | outputs a, x, z, n
4141 | {
4242 | ld x, 0
4343 | }
4444 ? UnmeaningfulOutputError: a
4545
46 | routine main
46 | define main routine
4747 | inputs a
4848 | outputs a
4949 | {
5353 If a routine declares it outputs a location, that location may or may not have
5454 been initialized. Trashing is mainly a signal to the caller.
5555
56 | routine main
56 | define main routine
5757 | trashes x, z, n
5858 | {
5959 | ld x, 0
6060 | }
6161 = ok
6262
63 | routine main
63 | define main routine
6464 | trashes x, z, n
6565 | {
6666 | }
6868
6969 If a routine modifies a location, it needs to either output it or trash it.
7070
71 | routine main
71 | define main routine
7272 | {
7373 | ld x, 0
7474 | }
7575 ? ForbiddenWriteError: x
7676
77 | routine main
77 | define main routine
7878 | outputs x, z, n
7979 | {
8080 | ld x, 0
8181 | }
8282 = ok
8383
84 | routine main
84 | define main routine
8585 | trashes x, z, n
8686 | {
8787 | ld x, 0
9090
9191 This is true regardless of whether it's an input or not.
9292
93 | routine main
93 | define main routine
9494 | inputs x
9595 | {
9696 | ld x, 0
9797 | }
9898 ? ForbiddenWriteError: x
9999
100 | routine main
100 | define main routine
101101 | inputs x
102102 | outputs x, z, n
103103 | {
105105 | }
106106 = ok
107107
108 | routine main
108 | define main routine
109109 | inputs x
110110 | trashes x, z, n
111111 | {
115115
116116 If a routine trashes a location, this must be declared.
117117
118 | routine foo
118 | define foo routine
119119 | trashes x
120120 | {
121121 | trash x
122122 | }
123123 = ok
124124
125 | routine foo
125 | define foo routine
126126 | {
127127 | trash x
128128 | }
129129 ? ForbiddenWriteError: x
130130
131 | routine foo
131 | define foo routine
132132 | outputs x
133133 | {
134134 | trash x
137137
138138 If a routine causes a location to be trashed, this must be declared in the caller.
139139
140 | routine trash_x
140 | define trash_x routine
141141 | trashes x, z, n
142142 | {
143143 | ld x, 0
144144 | }
145145 |
146 | routine foo
146 | define foo routine
147147 | trashes x, z, n
148148 | {
149149 | call trash_x
150150 | }
151151 = ok
152152
153 | routine trash_x
153 | define trash_x routine
154154 | trashes x, z, n
155155 | {
156156 | ld x, 0
157157 | }
158158 |
159 | routine foo
159 | define foo routine
160160 | trashes z, n
161161 | {
162162 | call trash_x
163163 | }
164164 ? ForbiddenWriteError: x
165165
166 | routine trash_x
166 | define trash_x routine
167167 | trashes x, z, n
168168 | {
169169 | ld x, 0
170170 | }
171171 |
172 | routine foo
172 | define foo routine
173173 | outputs x
174174 | trashes z, n
175175 | {
184184 | word w1 @ 60001
185185 | word w2 : 2000
186186 |
187 | routine main
187 | define main routine
188188 | inputs b1, w1
189189 | outputs b2, w2
190190 | trashes a, z, n
201201
202202 | byte up
203203 |
204 | routine main outputs x, y trashes z, n {
204 | define main routine outputs x, y trashes z, n {
205205 | ld x, 0
206206 | ld y, 1
207207 | call up
208208 | }
209209 ? TypeMismatchError: up
210210
211 | routine main outputs x, y trashes z, n {
211 | define main routine outputs x, y trashes z, n {
212212 | ld x, 0
213213 | ld y, 1
214214 | call x
219219
220220 | byte foo
221221 |
222 | routine main {
222 | define main routine {
223223 | goto foo
224224 | }
225225 ? TypeMismatchError: foo
228228
229229 Can't `ld` from a memory location that isn't initialized.
230230
231 | routine main
231 | define main routine
232232 | inputs a, x
233233 | trashes a, z, n
234234 | {
236236 | }
237237 = ok
238238
239 | routine main
239 | define main routine
240240 | inputs a
241241 | trashes a
242242 | {
246246
247247 Can't `ld` to a memory location that doesn't appear in (outputs ∪ trashes).
248248
249 | routine main
249 | define main routine
250250 | trashes a, z, n
251251 | {
252252 | ld a, 0
253253 | }
254254 = ok
255255
256 | routine main
256 | define main routine
257257 | outputs a
258258 | trashes z, n
259259 | {
261261 | }
262262 = ok
263263
264 | routine main
264 | define main routine
265265 | outputs z, n
266266 | trashes a
267267 | {
269269 | }
270270 = ok
271271
272 | routine main
272 | define main routine
273273 | trashes z, n
274274 | {
275275 | ld a, 0
276276 | }
277277 ? ForbiddenWriteError: a
278278
279 | routine main
279 | define main routine
280280 | trashes a, n
281281 | {
282282 | ld a, 0
287287
288288 | word foo
289289 |
290 | routine main
290 | define main routine
291291 | inputs foo
292292 | trashes a, n, z
293293 | {
300300 Can't `st` from a memory location that isn't initialized.
301301
302302 | byte lives
303 | routine main
303 | define main routine
304304 | inputs x
305305 | trashes lives
306306 | {
309309 = ok
310310
311311 | byte lives
312 | routine main
312 | define main routine
313313 | trashes x, lives
314314 | {
315315 | st x, lives
319319 Can't `st` to a memory location that doesn't appear in (outputs ∪ trashes).
320320
321321 | byte lives
322 | routine main
322 | define main routine
323323 | trashes lives
324324 | {
325325 | st 0, lives
327327 = ok
328328
329329 | byte lives
330 | routine main
330 | define main routine
331331 | outputs lives
332332 | {
333333 | st 0, lives
335335 = ok
336336
337337 | byte lives
338 | routine main
338 | define main routine
339339 | inputs lives
340340 | {
341341 | st 0, lives
346346
347347 | word foo
348348 |
349 | routine main
349 | define main routine
350350 | outputs foo
351351 | trashes a, n, z
352352 | {
362362 | byte one
363363 | byte table[256] many
364364 |
365 | routine main
365 | define main routine
366366 | outputs one
367367 | trashes a, x, n, z
368368 | {
375375 | byte one
376376 | byte table[256] many
377377 |
378 | routine main
378 | define main routine
379379 | outputs many
380380 | trashes a, x, n, z
381381 | {
388388 | byte one
389389 | byte table[256] many
390390 |
391 | routine main
391 | define main routine
392392 | outputs one
393393 | trashes a, x, n, z
394394 | {
401401 | byte one
402402 | byte table[256] many
403403 |
404 | routine main
404 | define main routine
405405 | outputs many
406406 | trashes a, x, n, z
407407 | {
416416 | byte one
417417 | byte table[256] many
418418 |
419 | routine main
419 | define main routine
420420 | outputs many
421421 | trashes a, x, n, z
422422 | {
429429
430430 | byte one
431431 |
432 | routine main
432 | define main routine
433433 | outputs one
434434 | trashes a, x, n, z
435435 | {
441441
442442 | byte one
443443 |
444 | routine main
444 | define main routine
445445 | outputs one
446446 | trashes a, x, n, z
447447 | {
453453
454454 | byte table[256] many
455455 |
456 | routine main
456 | define main routine
457457 | outputs many
458458 | trashes a, x, n, z
459459 | {
466466
467467 | byte table[256] many
468468 |
469 | routine main
469 | define main routine
470470 | outputs many
471471 | trashes a, x, n, z
472472 | {
479479
480480 | byte table[256] many
481481 |
482 | routine main
482 | define main routine
483483 | inputs many
484484 | outputs many
485485 | trashes a, x, n, z
493493
494494 | byte table[256] many
495495 |
496 | routine main
496 | define main routine
497497 | inputs many
498498 | outputs many
499499 | trashes a, x, n, z
506506
507507 | byte table[256] many
508508 |
509 | routine main
509 | define main routine
510510 | inputs many
511511 | outputs many
512512 | trashes a, x, c, n, z, v
524524
525525 | byte table[256] many
526526 |
527 | routine main
527 | define main routine
528528 | inputs many
529529 | outputs many
530530 | trashes a, x, c, n, z
541541
542542 | byte table[256] many
543543 |
544 | routine main
544 | define main routine
545545 | inputs many
546546 | outputs many
547547 | trashes a, x, c, n, z
561561 | word one
562562 | word table[256] many
563563 |
564 | routine main
564 | define main routine
565565 | inputs one, many
566566 | outputs one, many
567567 | trashes a, x, n, z
575575 | word one
576576 | word table[256] many
577577 |
578 | routine main
578 | define main routine
579579 | inputs one, many
580580 | outputs one, many
581581 | trashes a, x, n, z
588588 | word one
589589 | word table[256] many
590590 |
591 | routine main
591 | define main routine
592592 | inputs one, many
593593 | outputs one, many
594594 | trashes a, x, n, z
603603
604604 | word table[32] many
605605 |
606 | routine main
606 | define main routine
607607 | inputs many
608608 | outputs many
609609 | trashes a, x, n, z
627627
628628 | byte table[32] many
629629 |
630 | routine main
630 | define main routine
631631 | inputs many
632632 | outputs many
633633 | trashes a, x, n, z
640640
641641 | byte table[32] many
642642 |
643 | routine main
643 | define main routine
644644 | inputs many
645645 | outputs many
646646 | trashes a, x, n, z
652652
653653 | byte table[32] many
654654 |
655 | routine main
655 | define main routine
656656 | inputs many
657657 | outputs many
658658 | trashes a, x, n, z
668668 | word one: 77
669669 | word table[32] many
670670 |
671 | routine main
671 | define main routine
672672 | inputs many, one
673673 | outputs many, one
674674 | trashes a, x, n, z
682682 | word one: 77
683683 | word table[32] many
684684 |
685 | routine main
685 | define main routine
686686 | inputs many, one
687687 | outputs many, one
688688 | trashes a, x, n, z
695695 | word one: 77
696696 | word table[32] many
697697 |
698 | routine main
698 | define main routine
699699 | inputs many, one
700700 | outputs many, one
701701 | trashes a, x, n, z
713713 | word one: 77
714714 | word table[32] many
715715 |
716 | routine main
716 | define main routine
717717 | inputs a, many, one
718718 | outputs many, one
719719 | trashes a, x, n, z
730730 | word one: 77
731731 | word table[32] many
732732 |
733 | routine main
733 | define main routine
734734 | inputs a, many, one
735735 | outputs many, one
736736 | trashes a, x, n, z
748748 | word one: 77
749749 | word table[32] many
750750 |
751 | routine main
751 | define main routine
752752 | inputs a, many, one
753753 | outputs many, one
754754 | trashes a, x, n, z
765765
766766 Can't `add` from or to a memory location that isn't initialized.
767767
768 | routine main
768 | define main routine
769769 | inputs a
770770 | outputs a
771771 | trashes c, z, v, n
776776 = ok
777777
778778 | byte lives
779 | routine main
779 | define main routine
780780 | inputs a
781781 | outputs a
782782 | trashes c, z, v, n
787787 ? UnmeaningfulReadError: lives
788788
789789 | byte lives
790 | routine main
790 | define main routine
791791 | inputs lives
792792 | outputs a
793793 | trashes c, z, v, n
799799
800800 Can't `add` to a memory location that isn't writeable.
801801
802 | routine main
802 | define main routine
803803 | inputs a
804804 | trashes c
805805 | {
811811 You can `add` a word constant to a word memory location.
812812
813813 | word score
814 | routine main
814 | define main routine
815815 | inputs a, score
816816 | outputs score
817817 | trashes a, c, z, v, n
824824 `add`ing a word constant to a word memory location trashes `a`.
825825
826826 | word score
827 | routine main
827 | define main routine
828828 | inputs a, score
829829 | outputs score, a
830830 | trashes c, z, v, n
837837 To be sure, `add`ing a word constant to a word memory location trashes `a`.
838838
839839 | word score
840 | routine main
840 | define main routine
841841 | inputs score
842842 | outputs score
843843 | trashes c, z, v, n
851851
852852 | word score
853853 | word delta
854 | routine main
854 | define main routine
855855 | inputs score, delta
856856 | outputs score
857857 | trashes a, c, z, v, n
865865
866866 | word score
867867 | word delta
868 | routine main
868 | define main routine
869869 | inputs score, delta
870870 | outputs score
871871 | trashes c, z, v, n
879879
880880 | pointer ptr
881881 | word delta
882 | routine main
882 | define main routine
883883 | inputs ptr, delta
884884 | outputs ptr
885885 | trashes a, c, z, v, n
894894
895895 | pointer ptr
896896 | word delta
897 | routine main
897 | define main routine
898898 | inputs ptr, delta
899899 | outputs ptr
900900 | trashes c, z, v, n
909909
910910 Can't `sub` from or to a memory location that isn't initialized.
911911
912 | routine main
912 | define main routine
913913 | inputs a
914914 | outputs a
915915 | trashes c, z, v, n
920920 = ok
921921
922922 | byte lives
923 | routine main
923 | define main routine
924924 | inputs a
925925 | outputs a
926926 | trashes c, z, v, n
931931 ? UnmeaningfulReadError: lives
932932
933933 | byte lives
934 | routine main
934 | define main routine
935935 | inputs lives
936936 | outputs a
937937 | trashes c, z, v, n
943943
944944 Can't `sub` to a memory location that isn't writeable.
945945
946 | routine main
946 | define main routine
947947 | inputs a
948948 | trashes c
949949 | {
955955 You can `sub` a word constant from a word memory location.
956956
957957 | word score
958 | routine main
958 | define main routine
959959 | inputs a, score
960960 | outputs score
961961 | trashes a, c, z, v, n
968968 `sub`ing a word constant from a word memory location trashes `a`.
969969
970970 | word score
971 | routine main
971 | define main routine
972972 | inputs a, score
973973 | outputs score, a
974974 | trashes c, z, v, n
982982
983983 | word score
984984 | word delta
985 | routine main
985 | define main routine
986986 | inputs score, delta
987987 | outputs score
988988 | trashes a, c, z, v, n
996996
997997 | word score
998998 | word delta
999 | routine main
999 | define main routine
10001000 | inputs score, delta
10011001 | outputs score
10021002 | trashes c, z, v, n
10101010
10111011 Location must be initialized and writeable.
10121012
1013 | routine main
1013 | define main routine
10141014 | outputs x
10151015 | trashes z, n
10161016 | {
10181018 | }
10191019 ? UnmeaningfulReadError: x
10201020
1021 | routine main
1021 | define main routine
10221022 | inputs x
10231023 | trashes z, n
10241024 | {
10261026 | }
10271027 ? ForbiddenWriteError: x
10281028
1029 | routine main
1029 | define main routine
10301030 | inputs x
10311031 | outputs x
10321032 | trashes z, n
10391039
10401040 | word foo
10411041 |
1042 | routine main
1042 | define main routine
10431043 | inputs foo
10441044 | outputs foo
10451045 | trashes z, n
10521052
10531053 Location must be initialized and writeable.
10541054
1055 | routine main
1055 | define main routine
10561056 | outputs x
10571057 | trashes z, n
10581058 | {
10601060 | }
10611061 ? UnmeaningfulReadError: x
10621062
1063 | routine main
1063 | define main routine
10641064 | inputs x
10651065 | trashes z, n
10661066 | {
10681068 | }
10691069 ? ForbiddenWriteError: x
10701070
1071 | routine main
1071 | define main routine
10721072 | inputs x
10731073 | outputs x
10741074 | trashes z, n
10811081
10821082 | word foo
10831083 |
1084 | routine main
1084 | define main routine
10851085 | inputs foo
10861086 | outputs foo
10871087 | trashes z, n
10941094
10951095 Some rudimentary tests for `cmp`.
10961096
1097 | routine main
1097 | define main routine
10981098 | inputs a
10991099 | trashes z, c, n
11001100 | {
11021102 | }
11031103 = ok
11041104
1105 | routine main
1105 | define main routine
11061106 | inputs a
11071107 | trashes z, n
11081108 | {
11101110 | }
11111111 ? ForbiddenWriteError: c
11121112
1113 | routine main
1113 | define main routine
11141114 | trashes z, c, n
11151115 | {
11161116 | cmp a, 4
11211121
11221122 Some rudimentary tests for `and`.
11231123
1124 | routine main
1124 | define main routine
11251125 | inputs a
11261126 | outputs a, z, n
11271127 | {
11291129 | }
11301130 = ok
11311131
1132 | routine main
1132 | define main routine
11331133 | inputs a
11341134 | trashes z, n
11351135 | {
11371137 | }
11381138 ? ForbiddenWriteError: a
11391139
1140 | routine main
1140 | define main routine
11411141 | trashes z, n
11421142 | {
11431143 | and a, 4
11481148
11491149 Some rudimentary tests for `or`.
11501150
1151 | routine main
1151 | define main routine
11521152 | inputs a
11531153 | outputs a, z, n
11541154 | {
11561156 | }
11571157 = ok
11581158
1159 | routine main
1159 | define main routine
11601160 | inputs a
11611161 | trashes z, n
11621162 | {
11641164 | }
11651165 ? ForbiddenWriteError: a
11661166
1167 | routine main
1167 | define main routine
11681168 | trashes z, n
11691169 | {
11701170 | or a, 4
11751175
11761176 Some rudimentary tests for `xor`.
11771177
1178 | routine main
1178 | define main routine
11791179 | inputs a
11801180 | outputs a, z, n
11811181 | {
11831183 | }
11841184 = ok
11851185
1186 | routine main
1186 | define main routine
11871187 | inputs a
11881188 | trashes z, n
11891189 | {
11911191 | }
11921192 ? ForbiddenWriteError: a
11931193
1194 | routine main
1194 | define main routine
11951195 | trashes z, n
11961196 | {
11971197 | xor a, 4
12031203 Some rudimentary tests for `shl`.
12041204
12051205 | byte foo
1206 | routine main
1206 | define main routine
12071207 | inputs foo, a, c
12081208 | outputs foo, a, c, z, n
12091209 | {
12121212 | }
12131213 = ok
12141214
1215 | routine main
1215 | define main routine
12161216 | inputs a, c
12171217 | outputs c, z, n
12181218 | {
12201220 | }
12211221 ? ForbiddenWriteError: a
12221222
1223 | routine main
1223 | define main routine
12241224 | inputs a
12251225 | outputs a, c, z, n
12261226 | {
12331233 Some rudimentary tests for `shr`.
12341234
12351235 | byte foo
1236 | routine main
1236 | define main routine
12371237 | inputs foo, a, c
12381238 | outputs foo, a, c, z, n
12391239 | {
12421242 | }
12431243 = ok
12441244
1245 | routine main
1245 | define main routine
12461246 | inputs a, c
12471247 | outputs c, z, n
12481248 | {
12501250 | }
12511251 ? ForbiddenWriteError: a
12521252
1253 | routine main
1253 | define main routine
12541254 | inputs a
12551255 | outputs a, c, z, n
12561256 | {
12621262
12631263 Some rudimentary tests for `nop`.
12641264
1265 | routine main
1265 | define main routine
12661266 | {
12671267 | nop
12681268 | }
12751275
12761276 | byte lives
12771277 |
1278 | routine foo
1278 | define foo routine
12791279 | inputs x
12801280 | trashes lives
12811281 | {
12821282 | st x, lives
12831283 | }
12841284 |
1285 | routine main
1285 | define main routine
12861286 | {
12871287 | call foo
12881288 | }
12921292
12931293 | byte lives
12941294 |
1295 | routine foo
1295 | define foo routine
12961296 | inputs x
12971297 | trashes lives
12981298 | {
12991299 | st x, lives
13001300 | }
13011301 |
1302 | routine main
1302 | define main routine
13031303 | outputs x, z, n
13041304 | {
13051305 | ld x, 0
13091309
13101310 | byte lives
13111311 |
1312 | routine foo
1312 | define foo routine
13131313 | inputs x
13141314 | trashes lives
13151315 | {
13161316 | st x, lives
13171317 | }
13181318 |
1319 | routine main
1319 | define main routine
13201320 | outputs x, z, n
13211321 | trashes lives
13221322 | {
13291329
13301330 | byte lives
13311331 |
1332 | routine foo
1332 | define foo routine
13331333 | inputs x
13341334 | trashes lives
13351335 | {
13361336 | st x, lives
13371337 | }
13381338 |
1339 | routine main
1339 | define main routine
13401340 | outputs x, z, n, lives
13411341 | {
13421342 | ld x, 0
13481348
13491349 | byte lives
13501350 |
1351 | routine foo
1351 | define foo routine
13521352 | inputs x
13531353 | trashes lives
13541354 | {
13551355 | st x, lives
13561356 | }
13571357 |
1358 | routine main
1358 | define main routine
13591359 | outputs x, z, n, lives
13601360 | {
13611361 | ld x, 0
13671367 If a routine declares outputs, they are initialized in the caller after
13681368 calling it.
13691369
1370 | routine foo
1370 | define foo routine
13711371 | outputs x, z, n
13721372 | {
13731373 | ld x, 0
13741374 | }
13751375 |
1376 | routine main
1376 | define main routine
13771377 | outputs a
13781378 | trashes x, z, n
13791379 | {
13821382 | }
13831383 = ok
13841384
1385 | routine foo
1386 | {
1387 | }
1388 |
1389 | routine main
1385 | define foo routine
1386 | {
1387 | }
1388 |
1389 | define main routine
13901390 | outputs a
13911391 | trashes x
13921392 | {
13981398 If a routine trashes locations, they are uninitialized in the caller after
13991399 calling it.
14001400
1401 | routine foo
1401 | define foo routine
14021402 | trashes x, z, n
14031403 | {
14041404 | ld x, 0
14051405 | }
14061406 = ok
14071407
1408 | routine foo
1408 | define foo routine
14091409 | trashes x, z, n
14101410 | {
14111411 | ld x, 0
14121412 | }
14131413 |
1414 | routine main
1414 | define main routine
14151415 | outputs a
14161416 | trashes x, z, n
14171417 | {
14281428 | trashes a
14291429 | @ 65490
14301430 |
1431 | routine main
1431 | define main routine
14321432 | trashes a, z, n
14331433 | {
14341434 | ld a, 65
14411441 | trashes a
14421442 | @ 65490
14431443 |
1444 | routine main
1444 | define main routine
14451445 | trashes a, z, n
14461446 | {
14471447 | call chrout
14531453 | trashes a
14541454 | @ 65490
14551455 |
1456 | routine main
1456 | define main routine
14571457 | trashes a, x, z, n
14581458 | {
14591459 | ld a, 65
14661466
14671467 Trash does nothing except indicate that we do not care about the value anymore.
14681468
1469 | routine foo
1469 | define foo routine
14701470 | inputs a
14711471 | outputs x
14721472 | trashes a, z, n
14771477 | }
14781478 = ok
14791479
1480 | routine foo
1480 | define foo routine
14811481 | inputs a
14821482 | outputs a, x
14831483 | trashes z, n
14881488 | }
14891489 ? UnmeaningfulOutputError: a
14901490
1491 | routine foo
1491 | define foo routine
14921492 | inputs a
14931493 | outputs x
14941494 | trashes a, z, n
15031503
15041504 Both blocks of an `if` are analyzed.
15051505
1506 | routine foo
1506 | define foo routine
15071507 | inputs a
15081508 | outputs x
15091509 | trashes a, z, n, c
15191519
15201520 If a location is initialized in one block, is must be initialized in the other as well.
15211521
1522 | routine foo
1522 | define foo routine
15231523 | inputs a
15241524 | outputs x
15251525 | trashes a, z, n, c
15331533 | }
15341534 ? InconsistentInitializationError: x
15351535
1536 | routine foo
1536 | define foo routine
15371537 | inputs a
15381538 | outputs x
15391539 | trashes a, z, n, c
15471547 | }
15481548 ? InconsistentInitializationError: x
15491549
1550 | routine foo
1550 | define foo routine
15511551 | inputs a
15521552 | outputs x
15531553 | trashes a, z, n, c
15661566 input to the routine, and it is initialized in one branch, it need not
15671567 be initialized in the other.
15681568
1569 | routine foo
1569 | define foo routine
15701570 | outputs x
15711571 | trashes a, z, n, c
15721572 | {
15811581 | }
15821582 = ok
15831583
1584 | routine foo
1584 | define foo routine
15851585 | inputs x
15861586 | outputs x
15871587 | trashes a, z, n, c
15981598
15991599 An `if` with a single block is analyzed as if it had an empty `else` block.
16001600
1601 | routine foo
1601 | define foo routine
16021602 | inputs a
16031603 | outputs x
16041604 | trashes a, z, n, c
16101610 | }
16111611 ? InconsistentInitializationError: x
16121612
1613 | routine foo
1613 | define foo routine
16141614 | inputs a
16151615 | outputs x
16161616 | trashes a, z, n, c
16231623 | }
16241624 = ok
16251625
1626 | routine foo
1626 | define foo routine
16271627 | inputs a
16281628 | outputs x
16291629 | trashes a, z, n, c
16401640 trashes {`a`} and the other branch trashes {`b`} then the whole `if` statement
16411641 trashes {`a`, `b`}.
16421642
1643 | routine foo
1643 | define foo routine
16441644 | inputs a, x, z
16451645 | trashes a, x
16461646 | {
16521652 | }
16531653 = ok
16541654
1655 | routine foo
1655 | define foo routine
16561656 | inputs a, x, z
16571657 | trashes a
16581658 | {
16641664 | }
16651665 ? ForbiddenWriteError: x (in foo, line 10)
16661666
1667 | routine foo
1667 | define foo routine
16681668 | inputs a, x, z
16691669 | trashes x
16701670 | {
16801680
16811681 Repeat loop.
16821682
1683 | routine main
1683 | define main routine
16841684 | outputs x, y, n, z, c
16851685 | {
16861686 | ld x, 0
16951695
16961696 You can initialize something inside the loop that was uninitialized outside.
16971697
1698 | routine main
1698 | define main routine
16991699 | outputs x, y, n, z, c
17001700 | {
17011701 | ld x, 0
17101710 But you can't UNinitialize something at the end of the loop that you need
17111711 initialized at the start.
17121712
1713 | routine foo
1713 | define foo routine
17141714 | trashes y
17151715 | {
17161716 | }
17171717 |
1718 | routine main
1718 | define main routine
17191719 | outputs x, y, n, z, c
17201720 | {
17211721 | ld x, 0
17351735 | word one : 0
17361736 | word two : 0
17371737 |
1738 | routine main
1738 | define main routine
17391739 | inputs one, two
17401740 | outputs two
17411741 | trashes a, z, n
17481748
17491749 The body of `repeat forever` can be empty.
17501750
1751 | routine main
1751 | define main routine
17521752 | {
17531753 | repeat {
17541754 | } forever
17571757
17581758 While `repeat` is most often used with `z`, it can also be used with `n`.
17591759
1760 | routine main
1760 | define main routine
17611761 | outputs y, n, z
17621762 | {
17631763 | ld y, 15
19331933
19341934 You can initialize something inside the loop that was uninitialized outside.
19351935
1936 | routine main
1936 | define main routine
19371937 | outputs x, y, n, z
19381938 | trashes c
19391939 | {
19471947 But you can't UNinitialize something at the end of the loop that you need
19481948 initialized at the start of that loop.
19491949
1950 | routine foo
1950 | define foo routine
19511951 | trashes y
19521952 | {
19531953 | }
19541954 |
1955 | routine main
1955 | define main routine
19561956 | outputs x, y, n, z
19571957 | trashes c
19581958 | {
19691969
19701970 Basic neutral test, where the `save` makes no difference.
19711971
1972 | routine main
1972 | define main routine
19731973 | inputs a, x
19741974 | outputs a, x
19751975 | trashes z, n
19841984
19851985 Saving any location (other than `a`) will trash `a`.
19861986
1987 | routine main
1987 | define main routine
19881988 | inputs a, x
19891989 | outputs a, x
19901990 | trashes z, n
19981998
19991999 Saving `a` does not trash anything.
20002000
2001 | routine main
2001 | define main routine
20022002 | inputs a, x
20032003 | outputs a, x
20042004 | trashes z, n
20142014 A defined value that has been saved can be trashed inside the block.
20152015 It will continue to be defined outside the block.
20162016
2017 | routine main
2017 | define main routine
20182018 | outputs x, y
20192019 | trashes a, z, n
20202020 | {
20312031
20322032 (Note, both x and a are unmeaningful in this test.)
20332033
2034 | routine main
2034 | define main routine
20352035 | inputs a
20362036 | outputs a, x
20372037 | trashes z, n
20502050 | word one: 77
20512051 | word table[32] many
20522052 |
2053 | routine main
2053 | define main routine
20542054 | inputs a, many, one
20552055 | outputs many, one
20562056 | trashes a, x, n, z
20682068 | word one: 77
20692069 | word table[32] many
20702070 |
2071 | routine main
2071 | define main routine
20722072 | inputs a, many, one
20732073 | outputs many, one
20742074 | trashes a, x, n, z
20882088 | word one: 77
20892089 | word table[32] many
20902090 |
2091 | routine main
2091 | define main routine
20922092 | inputs a, many, one
20932093 | outputs many, one
20942094 | trashes a, x, n, z
21072107 A value which is not output from the routine, is preserved by the
21082108 routine; and can appear in a `save` exactly because a `save` preserves it.
21092109
2110 | routine main
2110 | define main routine
21112111 | outputs y
21122112 | trashes a, z, n
21132113 | {
21212121 Because saving anything except `a` trashes `a`, a common idiom is to save `a`
21222122 first in a nested series of `save`s.
21232123
2124 | routine main
2124 | define main routine
21252125 | inputs a
21262126 | outputs a
21272127 | trashes z, n
21372137
21382138 There is a shortcut syntax for a nested series of `save`s.
21392139
2140 | routine main
2140 | define main routine
21412141 | inputs a
21422142 | outputs a
21432143 | trashes z, n
21512151
21522152 `a` is only preserved if it is the outermost thing `save`d.
21532153
2154 | routine main
2154 | define main routine
21552155 | inputs a
21562156 | outputs a
21572157 | trashes z, n
21672167
21682168 | byte foo
21692169 |
2170 | routine main
2170 | define main routine
21712171 | trashes a, z, n
21722172 | {
21732173 | save foo {
21802180
21812181 | word foo
21822182 |
2183 | routine main
2183 | define main routine
21842184 | trashes a, z, n
21852185 | {
21862186 | save foo {
21912191
21922192 | byte table[16] tab
21932193 |
2194 | routine main
2194 | define main routine
21952195 | trashes a, y, z, n
21962196 | {
21972197 | save tab {
22032203
22042204 A `goto` cannot appear within a `save` block, even if it is otherwise in tail position.
22052205
2206 | routine other
2206 | define other routine
22072207 | trashes a, z, n
22082208 | {
22092209 | ld a, 0
22102210 | }
22112211 |
2212 | routine main
2212 | define main routine
22132213 | trashes a, z, n
22142214 | {
22152215 | ld a, 1
22282228 | trashes z, n
22292229 | bar
22302230 |
2231 | routine foo
2231 | define foo routine
22322232 | inputs x
22332233 | outputs x
22342234 | trashes z, n
22362236 | inc x
22372237 | }
22382238 |
2239 | routine main
2239 | define main routine
22402240 | outputs bar
22412241 | trashes a, n, z
22422242 | {
22552255 | trashes z, n
22562256 | bar
22572257 |
2258 | routine foo
2258 | define foo routine
22592259 | inputs x
22602260 | outputs x
22612261 | trashes z, n
22692269 | ld a, 0
22702270 | }
22712271 |
2272 | routine main
2272 | define main routine
22732273 | trashes bar, a, n, z
22742274 | {
22752275 | with interrupts off {
22842284 Can't `copy` from a memory location that isn't initialized.
22852285
22862286 | byte lives
2287 | routine main
2287 | define main routine
22882288 | inputs x
22892289 | outputs lives
22902290 | trashes a, z, n
22942294 = ok
22952295
22962296 | byte lives
2297 | routine main
2297 | define main routine
22982298 | outputs lives
22992299 | trashes x, a, z, n
23002300 | {
23052305 Can't `copy` to a memory location that doesn't appear in (outputs ∪ trashes).
23062306
23072307 | byte lives
2308 | routine main
2308 | define main routine
23092309 | trashes lives, a, z, n
23102310 | {
23112311 | copy 0, lives
23132313 = ok
23142314
23152315 | byte lives
2316 | routine main
2316 | define main routine
23172317 | outputs lives
23182318 | trashes a, z, n
23192319 | {
23222322 = ok
23232323
23242324 | byte lives
2325 | routine main
2325 | define main routine
23262326 | inputs lives
23272327 | trashes a, z, n
23282328 | {
23352335 (Note, both n and z are forbidden writes in this test.)
23362336
23372337 | byte lives
2338 | routine main
2338 | define main routine
23392339 | outputs lives
23402340 | {
23412341 | copy 0, lives
23472347 (Note, both n and a are unmeaningful outputs in this test.)
23482348
23492349 | byte lives
2350 | routine main
2350 | define main routine
23512351 | outputs lives, a, z, n
23522352 | {
23532353 | copy 0, lives
23572357 Unless of course you subsequently initialize them.
23582358
23592359 | byte lives
2360 | routine main
2360 | define main routine
23612361 | outputs lives, a, z, n
23622362 | {
23632363 | copy 0, lives
23702370 | byte source : 0
23712371 | byte dest
23722372 |
2373 | routine main
2373 | define main routine
23742374 | inputs source
23752375 | outputs dest
23762376 | trashes a, z, n
23852385 | byte source : 0
23862386 | byte dest
23872387 |
2388 | routine main
2388 | define main routine
23892389 | inputs source
23902390 | outputs dest
23912391 | trashes a, z, n
23992399 | word source : 0
24002400 | word dest
24012401 |
2402 | routine main
2402 | define main routine
24032403 | inputs source
24042404 | outputs dest
24052405 | trashes a, z, n
24132413 | byte source : 0
24142414 | word dest
24152415 |
2416 | routine main
2416 | define main routine
24172417 | inputs source
24182418 | outputs dest
24192419 | trashes a, z, n
24272427 | word source : 0
24282428 | byte dest
24292429 |
2430 | routine main
2430 | define main routine
24312431 | inputs source
24322432 | outputs dest
24332433 | trashes a, z, n
24582458 | buffer[2048] buf
24592459 | pointer ptr
24602460 |
2461 | routine main
2461 | define main routine
24622462 | inputs buf
24632463 | outputs y, buf
24642464 | trashes a, z, n, ptr
24742474 | buffer[2048] buf
24752475 | pointer ptr
24762476 |
2477 | routine main
2477 | define main routine
24782478 | inputs buf
24792479 | outputs buf
24802480 | trashes a, z, n, ptr
24902490 | pointer ptr
24912491 | byte foo
24922492 |
2493 | routine main
2493 | define main routine
24942494 | inputs foo, buf
24952495 | outputs y, buf
24962496 | trashes a, z, n, ptr
25072507 | pointer ptr
25082508 | byte foo
25092509 |
2510 | routine main
2510 | define main routine
25112511 | inputs buf
25122512 | outputs foo
25132513 | trashes a, y, z, n, ptr
25242524 | pointer ptra
25252525 | pointer ptrb
25262526 |
2527 | routine main
2527 | define main routine
25282528 | inputs buf
25292529 | outputs buf
25302530 | trashes a, y, z, n, ptra, ptrb
25432543 | pointer ptr
25442544 | byte foo
25452545 |
2546 | routine main
2546 | define main routine
25472547 | inputs buf
25482548 | outputs a
25492549 | trashes y, z, n, ptr
25612561 | pointer ptr
25622562 | byte foo
25632563 |
2564 | routine main
2564 | define main routine
25652565 | inputs buf
25662566 | outputs buf
25672567 | trashes a, y, z, n, ptr
25842584 | trashes z, n
25852585 | vec
25862586 |
2587 | routine foo
2587 | define foo routine
25882588 | inputs x
25892589 | outputs x
25902590 | trashes z, n
25922592 | inc x
25932593 | }
25942594 |
2595 | routine main
2595 | define main routine
25962596 | inputs foo
25972597 | outputs vec
25982598 | trashes a, z, n
26072607 | trashes z, n
26082608 | vec
26092609 |
2610 | routine foo
2610 | define foo routine
26112611 | inputs x
26122612 | outputs x
26132613 | trashes z, n
26152615 | inc x
26162616 | }
26172617 |
2618 | routine main
2618 | define main routine
26192619 | outputs vec, foo
26202620 | trashes a, z, n
26212621 | {
26292629 | trashes z, n
26302630 | vec
26312631 |
2632 | routine foo
2632 | define foo routine
26332633 | inputs x
26342634 | outputs x
26352635 | trashes z, n
26372637 | inc x
26382638 | }
26392639 |
2640 | routine main
2640 | define main routine
26412641 | outputs vec
26422642 | trashes a, z, n, foo
26432643 | {
26622662 | trashes z, n
26632663 | vec
26642664 |
2665 | routine foo
2665 | define foo routine
26662666 | inputs x, y
26672667 | outputs x, y
26682668 | trashes z, n
26712671 | inc y
26722672 | }
26732673 |
2674 | routine main
2674 | define main routine
26752675 | outputs vec
26762676 | trashes a, z, n
26772677 | {
26892689 | trashes z, n
26902690 | vec
26912691 |
2692 | routine foo
2692 | define foo routine
26932693 | inputs x, y
26942694 | outputs x, y
26952695 | trashes z, n
26982698 | inc y
26992699 | }
27002700 |
2701 | routine main
2701 | define main routine
27022702 | outputs vec
27032703 | trashes a, z, n
27042704 | {
27142714 | trashes z, n
27152715 | vec
27162716 |
2717 | routine foo
2717 | define foo routine
27182718 | inputs x, y
27192719 | outputs x, y
27202720 | trashes z, n
27232723 | inc y
27242724 | }
27252725 |
2726 | routine main
2726 | define main routine
27272727 | outputs vec
27282728 | trashes a, z, n
27292729 | {
27422742 | trashes z, n
27432743 | vec
27442744 |
2745 | routine foo
2745 | define foo routine
27462746 | inputs x, y
27472747 | outputs x, y
27482748 | trashes z, n
27512751 | inc y
27522752 | }
27532753 |
2754 | routine main
2754 | define main routine
27552755 | outputs vec
27562756 | trashes a, z, n
27572757 | {
27672767 | trashes z, n
27682768 | vec
27692769 |
2770 | routine foo
2770 | define foo routine
27712771 | inputs x, y
27722772 | outputs x, y
27732773 | trashes z, n
27762776 | inc y
27772777 | }
27782778 |
2779 | routine main
2779 | define main routine
27802780 | outputs vec
27812781 | trashes a, z, n
27822782 | {
27922792 | trashes z
27932793 | vec
27942794 |
2795 | routine foo
2795 | define foo routine
27962796 | inputs x, y
27972797 | outputs x, y
27982798 | trashes z, n
28012801 | inc y
28022802 | }
28032803 |
2804 | routine main
2804 | define main routine
28052805 | outputs vec
28062806 | trashes a, z, n
28072807 | {
28202820 | trashes a, z, n
28212821 | vec
28222822 |
2823 | routine foo
2823 | define foo routine
28242824 | inputs x, y
28252825 | outputs x, y
28262826 | trashes z, n
28292829 | inc y
28302830 | }
28312831 |
2832 | routine main
2832 | define main routine
28332833 | outputs vec
28342834 | trashes a, z, n
28352835 | {
28472847 | trashes z, n
28482848 | vec
28492849 |
2850 | routine foo
2850 | define foo routine
28512851 | inputs x
28522852 | outputs x
28532853 | trashes z, n
28552855 | inc x
28562856 | }
28572857 |
2858 | routine main
2858 | define main routine
28592859 | outputs vec
28602860 | trashes a, z, n
28612861 | {
28692869 | outputs x trashes z, n
28702870 | foo
28712871 |
2872 | routine bar outputs x trashes z, n {
2872 | define bar routine outputs x trashes z, n {
28732873 | ld x, 200
28742874 | }
28752875 |
2876 | routine main outputs x, foo trashes a, z, n {
2876 | define main routine outputs x, foo trashes a, z, n {
28772877 | copy bar, foo
28782878 | call foo
28792879 | }
30703070 | outputs x
30713071 | trashes a, z, n foo
30723072 |
3073 | routine bar
3073 | define bar routine
30743074 | outputs x
30753075 | trashes a, z, n {
30763076 | ld x, 200
30773077 | }
30783078 |
3079 | routine sub
3079 | define sub routine
30803080 | outputs x
30813081 | trashes foo, a, z, n {
30823082 | ld x, 0
30843084 | goto foo
30853085 | }
30863086 |
3087 | routine main
3087 | define main routine
30883088 | outputs a
30893089 | trashes foo, x, z, n {
30903090 | call sub
31053105 | trashes a, z, n)
31063106 | table[256] many
31073107 |
3108 | routine bar outputs x trashes a, z, n {
3108 | define bar routine outputs x trashes a, z, n {
31093109 | ld x, 200
31103110 | }
31113111 |
3112 | routine main
3112 | define main routine
31133113 | inputs one, many
31143114 | outputs one, many
31153115 | trashes a, x, n, z
31313131 | trashes a, z, n)
31323132 | table[256] many
31333133 |
3134 | routine bar outputs x trashes a, z, n {
3134 | define bar routine outputs x trashes a, z, n {
31353135 | ld x, 200
31363136 | }
31373137 |
3138 | routine main
3138 | define main routine
31393139 | inputs one, many
31403140 | outputs one, many
31413141 | trashes a, x, n, z
31533153 | trashes a, z, n)
31543154 | table[256] many
31553155 |
3156 | routine bar outputs x trashes a, z, n {
3156 | define bar routine outputs x trashes a, z, n {
31573157 | ld x, 200
31583158 | }
31593159 |
3160 | routine main
3160 | define main routine
31613161 | inputs many
31623162 | outputs many
31633163 | trashes a, x, n, z
31783178 | ld x, 200
31793179 | }
31803180 |
3181 | routine main
3181 | define main routine
31823182 | inputs many
31833183 | outputs many
31843184 | trashes a, x, n, z
32023202 |
32033203 | vector routine_type vec
32043204 |
3205 | routine foo
3205 | define foo routine
32063206 | inputs x
32073207 | outputs x
32083208 | trashes z, n
32103210 | inc x
32113211 | }
32123212 |
3213 | routine main
3213 | define main routine
32143214 | outputs vec
32153215 | trashes a, z, n
32163216 | {
32333233 | inc x
32343234 | }
32353235 |
3236 | routine main
3236 | define main routine
32373237 | outputs vec
32383238 | trashes a, z, n
32393239 | {