annotate ppc/test/array.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* array.p *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 var i: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 var a: array 10 of integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 proc foo();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 var j: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 var b : array 10 of integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 print_string("foo"); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 j := 2; b[0] := 1; b[1] := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 while 10 > j do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 b[j] := b[j-2] + b[j-1];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 print_char(' '); print_num(b[j]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 j := 1+j
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 print_string("baz"); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 i := 2; a[0] := 1; a[1] := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 while i < 10 do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 a[i] := a[i-2] + a[i-1];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 print_char(' '); print_num(a[i]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 foo()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 baz
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 2 3 5 8 13 21 34 55
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 foo
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 2 3 5 8 13 21 34 55
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 PROC _foo 44 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 ! print_string("foo"); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 GLOBAL g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 ! j := 2; b[0] := 1; b[1] := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 STLW -44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 STLW -40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 ! while 10 > j do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 JUMP L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 LABEL L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 ! b[j] := b[j-2] + b[j-1];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 LOCAL -44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 LOCAL -44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 LOCAL -44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 STIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 ! print_char(' '); print_num(b[j]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 CONST 32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 GLOBAL lib.print_char
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 LOCAL -44
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 ! j := 1+j
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 LABEL L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 CONST 10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 JGT L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 ! newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 ! end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 ! print_string("baz"); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 GLOBAL g2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 ! i := 2; a[0] := 1; a[1] := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 STGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 STGW _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 STNW 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 ! while i < 10 do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127 JUMP L7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128 LABEL L6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129 ! a[i] := a[i-2] + a[i-1];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 STIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144 ! print_char(' '); print_num(a[i]);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 CONST 32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
147 GLOBAL lib.print_char
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
148 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
149 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
150 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
151 LDIW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
152 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
153 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
154 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
155 ! i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
156 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
157 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
158 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
159 STGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
160 LABEL L7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
161 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
162 CONST 10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
163 JLT L6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
164 ! newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
165 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
166 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
167 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
168 ! foo()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
169 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
170 GLOBAL _foo
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
171 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
172 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
173 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
174
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
175 GLOVAR _i 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
176 GLOVAR _a 40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
177 ! String "foo"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
178 DEFINE g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
179 STRING 666F6F00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
180
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
181 ! String "baz"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
182 DEFINE g2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
183 STRING 62617A00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
184
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
185 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
186 ]]*)