annotate lab4/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 @ picoPascal compiler output
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
152 .include "fixup.s"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
153 .global pmain
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
154
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
155 @ proc queens(k: integer; proc choice(x: integer): integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
156 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
157 _queens:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
158 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
159 stmfd sp!, {r0-r3}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
160 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
161 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
162 sub sp, sp, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
163 @ if k > N then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
164 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
165 cmp r0, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
166 ble .L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
167 @ print(choice)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
168 ldr r1, [fp, #48]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
169 ldr r0, [fp, #44]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
170 bl _print
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
171 b .L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
172 .L3:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
173 @ y := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
174 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
175 str r0, [fp, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
176 .L5:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
177 @ while y <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
178 ldr r0, [fp, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
179 cmp r0, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
180 bgt .L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
181 @ j := 1; ok := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
182 mov r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
183 mov r6, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
184 .L8:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
185 @ while ok and (j < k) do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
186 cmp r6, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
187 beq .L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
188 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
189 cmp r4, r0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
190 bge .L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
191 @ q := choice(j);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
192 mov r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
193 ldr r10, [fp, #48]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
194 ldr r1, [fp, #44]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
195 blx r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
196 mov r5, r0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
197 @ ok := (q <> y) and (q+j <> y+k) and (q-j <> y-k);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
198 ldr r7, [fp, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
199 ldr r8, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
200 cmp r5, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
201 mov r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
202 movne r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
203 add r1, r5, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
204 add r2, r7, r8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
205 cmp r1, r2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
206 mov r1, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
207 movne r1, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
208 and r0, r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
209 sub r1, r5, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
210 sub r2, r7, r8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
211 cmp r1, r2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
212 mov r1, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
213 movne r1, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
214 and r6, r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
215 @ j := j+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
216 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
217 b .L8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
218 .L10:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
219 @ if ok then queens(k+1, choice1) end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
220 cmp r6, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
221 beq .L14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
222 mov r2, fp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
223 set r1, _choice1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
224 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
225 add r0, r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
226 bl _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
227 .L14:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
228 @ y := y+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
229 ldr r0, [fp, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
230 add r0, r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
231 str r0, [fp, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
232 b .L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
233 .L1:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
234 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
235 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
236
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
237 @ proc choice1(x: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
238 _choice1:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
239 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
240 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
241 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
242 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
243 @ if x = k then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
244 ldr r4, [fp, #24]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
245 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
246 ldr r1, [r4, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
247 cmp r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
248 bne .L17
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
249 @ return y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
250 ldr r0, [r4, #-4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
251 b .L15
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
252 .L17:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
253 @ return choice(x)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
254 ldr r4, [fp, #24]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
255 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
256 ldr r10, [r4, #48]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
257 ldr r1, [r4, #44]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
258 blx r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
259 .L15:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
260 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
261 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
262
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
263 @ proc print(proc choice(x: integer): integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
264 _print:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
265 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
266 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
267 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
268 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
269 @ x := 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
270 mov r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
271 .L20:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
272 @ while x <= N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
273 cmp r4, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
274 bgt .L22
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
275 @ print_num(choice(x));
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
276 mov r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
277 ldr r10, [fp, #44]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
278 ldr r1, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
279 blx r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
280 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
281 @ x := x+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
282 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
283 b .L20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
284 .L22:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
285 @ newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
286 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
287 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
288 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
289
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
290 @ proc choice0(x: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
291 _choice0:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
292 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
293 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
294 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
295 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
296 @ return 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
297 mov r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
298 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
299 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
300
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
301 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
302 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
303 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
304 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
305 @ queens(1, choice0)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
306 mov r2, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
307 set r1, _choice0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
308 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
309 bl _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
310 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
311 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
312
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
313 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
314 ]]*)