annotate ppc/test/queens.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 (* N queens in functional form *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 const N = 8;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 proc queens(k: integer; proc choice(x: integer): integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 var y, j, q: integer; ok: boolean;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 proc choice1(x: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 if x = k then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 return y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 return choice(x)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 if k > N then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 print(choice)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 y := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 while y <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 j := 1; ok := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 while ok and (j < k) do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 q := choice(j);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 ok := (q <> y) and (q+j <> y+k) and (q-j <> y-k);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 j := j+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 if ok then queens(k+1, choice1) end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 y := y+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 proc print(proc choice(x: integer): integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 var x: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 x := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 while x <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 print_num(choice(x));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 x := x+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 proc choice0(x: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 return 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 queens(1, choice0)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 15863724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 16837425
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 17468253
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 17582463
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 24683175
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 25713864
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 25741863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 26174835
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 26831475
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 27368514
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 27581463
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 28613574
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 31758246
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 35281746
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 35286471
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 35714286
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 35841726
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 36258174
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 36271485
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 36275184
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 36418572
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 36428571
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 36814752
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 36815724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 36824175
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 37285146
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 37286415
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 38471625
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 41582736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 41586372
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 42586137
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 42736815
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 42736851
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 42751863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 42857136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 42861357
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 46152837
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 46827135
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 46831752
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 47185263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 47382516
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 47526138
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 47531682
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 48136275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 48157263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 48531726
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 51468273
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 51842736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 51863724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 52468317
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 52473861
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 52617483
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 52814736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 53168247
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 53172864
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 53847162
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 57138642
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 57142863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 57248136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 57263148
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 57263184
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 57413862
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 58413627
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 58417263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 61528374
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 62713584
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 62714853
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 63175824
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124 63184275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 63185247
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 63571428
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127 63581427
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128 63724815
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129 63728514
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 63741825
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 64158273
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 64285713
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133 64713528
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 64718253
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 68241753
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136 71386425
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 72418536
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138 72631485
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139 73168524
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140 73825164
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 74258136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142 74286135
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 75316824
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144 82417536
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 82531746
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 83162574
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
147 84136275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
148 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
149
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
150 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
151 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
152 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
153 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
154
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
155 PROC _queens 16 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
156 ! if k > N then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
157 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
158 CONST 8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
159 JLEQ L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
160 ! print(choice)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
161 LDLW 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
162 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
163 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
164 GLOBAL _print
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
165 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
166 JUMP L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
167 LABEL L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
168 ! y := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
169 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
170 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
171 ! while y <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
172 JUMP L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
173 LABEL L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
174 ! j := 1; ok := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
175 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
176 STLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
177 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
178 STLC -13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
179 ! while ok and (j < k) do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
180 JUMP L8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
181 LABEL L7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
182 ! q := choice(j);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
183 LDLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
184 LDLW 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
185 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
186 PCALLW 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
187 STLW -12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
188 ! ok := (q <> y) and (q+j <> y+k) and (q-j <> y-k);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
189 LDLW -12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
190 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
191 JEQ L12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
192 LDLW -12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
193 LDLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
194 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
195 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
196 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
197 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
198 JEQ L12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
199 LDLW -12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
200 LDLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
201 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
202 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
203 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
204 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
205 JEQ L12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
206 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
207 JUMP L13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
208 LABEL L12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
209 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
210 LABEL L13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
211 STLC -13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
212 ! j := j+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
213 LDLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
214 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
215 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
216 STLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
217 LABEL L8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
218 LDLC -13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
219 JNEQZ L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
220 JUMP L9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
221 LABEL L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
222 LDLW -8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
223 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
224 JLT L7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
225 LABEL L9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
226 ! if ok then queens(k+1, choice1) end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
227 LDLC -13
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
228 JNEQZ L16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
229 JUMP L18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
230 LABEL L16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
231 LOCAL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
232 GLOBAL _choice1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
233 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
234 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
235 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
236 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
237 GLOBAL _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
238 PCALL 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
239 LABEL L18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
240 ! y := y+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
241 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
242 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
243 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
244 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
245 LABEL L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
246 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
247 CONST 8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
248 JLEQ L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
249 LABEL L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
250 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
251 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
252
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
253 PROC _choice1 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
254 ! if x = k then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
255 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
256 LDLW 12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
257 LDNW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
258 JNEQ L20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
259 ! return y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
260 LDLW 12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
261 LDNW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
262 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
263 LABEL L20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
264 ! return choice(x)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
265 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
266 LDLW 12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
267 LDNW 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
268 LDLW 12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
269 LDNW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
270 PCALLW 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
271 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
272 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
273
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
274 PROC _print 4 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
275 ! x := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
276 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
277 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
278 ! while x <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
279 JUMP L23
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
280 LABEL L22
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
281 ! print_num(choice(x));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
282 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
283 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
284 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
285 PCALLW 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
286 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
287 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
288 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
289 ! x := x+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
290 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
291 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
292 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
293 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
294 LABEL L23
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
295 LDLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
296 CONST 8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
297 JLEQ L22
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
298 ! newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
299 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
300 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
301 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
302 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
303 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
304
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
305 PROC _choice0 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
306 ! return 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
307 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
308 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
309 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
310
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
311 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
312 ! queens(1, choice0)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
313 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
314 GLOBAL _choice0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
315 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
316 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
317 GLOBAL _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
318 PCALL 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
319 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
320 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
321
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
322 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
323 ]]*)