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