annotate lab4/test/queens3.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 with bitmap arrays *)
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 var
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 choice: array N of integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 rank: array N of boolean;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 diagup, diagdown: array 2 * N - 1 of boolean;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 proc queens(k: integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 var y, j, q: integer; ok: boolean;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 if k = N then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 print()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 y := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 while y < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 if rank[y] and diagup[k+y] and diagdown[k+(N-1)-y] then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 rank[y] := false; diagup[k+y] := false; diagdown[k+(N-1)-y] := false;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 choice[k] := y; queens(k+1);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 rank[y] := true; diagup[k+y] := true; diagdown[k+(N-1)-y] := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 y := y+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 proc print();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 var x: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 x := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 while x < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 print_num(choice[x]+1);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 x := x+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 proc init();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 var i: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 while i < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 rank[i] := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 while i < 2*N-1 do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 diagup[i] := true; diagdown[i] := true ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 init();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 queens(0)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 15863724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 16837425
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 17468253
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 17582463
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 24683175
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 25713864
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 25741863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 26174835
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 26831475
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 27368514
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 27581463
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 28613574
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 31758246
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 35281746
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 35286471
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 35714286
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 35841726
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 36258174
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 36271485
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 36275184
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 36418572
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 36428571
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 36814752
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 36815724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 36824175
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 37285146
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 37286415
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 38471625
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 41582736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 41586372
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 42586137
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 42736815
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 42736851
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 42751863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 42857136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 42861357
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 46152837
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 46827135
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 46831752
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 47185263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 47382516
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 47526138
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 47531682
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 48136275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 48157263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 48531726
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 51468273
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 51842736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 51863724
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 52468317
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 52473861
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 52617483
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 52814736
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 53168247
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 53172864
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 53847162
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 57138642
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 57142863
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 57248136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 57263148
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 57263184
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 57413862
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 58413627
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 58417263
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124 61528374
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 62713584
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 62714853
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127 63175824
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128 63184275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129 63185247
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 63571428
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 63581427
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 63724815
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133 63728514
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 63741825
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 64158273
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136 64285713
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 64713528
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138 64718253
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139 68241753
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140 71386425
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 72418536
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142 72631485
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 73168524
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144 73825164
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 74258136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 74286135
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
147 75316824
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
148 82417536
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
149 82531746
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
150 83162574
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
151 84136275
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
152 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
153
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
154 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
155 @ picoPascal compiler output
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
156 .include "fixup.s"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
157 .global pmain
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
158
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
159 @ proc queens(k: integer);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
160 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
161 _queens:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
162 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
163 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
164 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
165 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
166 sub sp, sp, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
167 @ if k = N then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
168 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
169 cmp r0, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
170 bne .L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
171 @ print()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
172 bl _print
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
173 b .L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
174 .L3:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
175 @ y := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
176 mov r4, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
177 .L5:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
178 @ while y < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
179 cmp r4, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
180 bge .L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
181 @ if rank[y] and diagup[k+y] and diagdown[k+(N-1)-y] then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
182 set r0, _rank
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
183 add r7, r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
184 ldrb r0, [r7]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
185 cmp r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
186 beq .L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
187 ldr r8, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
188 set r0, _diagup
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
189 add r0, r0, r8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
190 add r9, r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
191 ldrb r0, [r9]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
192 cmp r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
193 beq .L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
194 set r0, _diagdown
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
195 add r1, r8, #7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
196 sub r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
197 add r0, r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
198 ldrb r1, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
199 cmp r1, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
200 beq .L10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
201 @ rank[y] := false; diagup[k+y] := false; diagdown[k+(N-1)-y] := false;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
202 mov r1, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
203 strb r1, [r7]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
204 mov r1, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
205 strb r1, [r9]
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 strb r1, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
208 @ choice[k] := y; queens(k+1);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
209 set r0, _choice
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
210 lsl r1, r8, #2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
211 add r0, r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
212 str r4, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
213 add r0, r8, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
214 bl _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
215 @ rank[y] := true; diagup[k+y] := true; diagdown[k+(N-1)-y] := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
216 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
217 set r1, _rank
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
218 add r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
219 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
220 ldr r7, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
221 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
222 set r1, _diagup
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
223 add r1, r1, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
224 add r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
225 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
226 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
227 set r1, _diagdown
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
228 add r2, r7, #7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
229 sub r2, r2, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
230 add r1, r1, r2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
231 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
232 .L10:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
233 @ y := y+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
234 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
235 b .L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
236 .L1:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
237 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
238 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
239
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
240 @ proc print();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
241 _print:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
242 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
243 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
244 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
245 @ x := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
246 mov r4, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
247 .L14:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
248 @ while x < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
249 cmp r4, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
250 bge .L16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
251 @ print_num(choice[x]+1);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
252 set r0, _choice
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
253 lsl r1, r4, #2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
254 add r0, r0, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
255 ldr r0, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
256 add r0, r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
257 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
258 @ x := x+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
259 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
260 b .L14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
261 .L16:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
262 @ newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
263 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
264 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
265 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
266
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
267 @ proc init();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
268 _init:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
269 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
270 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
271 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
272 @ i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
273 mov r4, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
274 .L18:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
275 @ while i < N do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
276 cmp r4, #8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
277 bge .L20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
278 @ rank[i] := true;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
279 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
280 set r1, _rank
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
281 add r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
282 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
283 @ i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
284 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
285 b .L18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
286 .L20:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
287 @ i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
288 mov r4, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
289 .L21:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
290 @ while i < 2*N-1 do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
291 cmp r4, #15
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
292 bge .L17
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
293 @ diagup[i] := true; diagdown[i] := true ;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
294 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
295 set r1, _diagup
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
296 add r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
297 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
298 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
299 set r1, _diagdown
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
300 add r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
301 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
302 @ i := i+1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
303 add r4, r4, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
304 b .L21
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
305 .L17:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
306 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
307 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
308
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
309 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
310 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
311 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
312 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
313 @ init();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
314 bl _init
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
315 @ queens(0)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
316 mov r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
317 bl _queens
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
318 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
319 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
320
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
321 .comm _choice, 32, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
322 .comm _rank, 8, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
323 .comm _diagup, 15, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
324 .comm _diagdown, 15, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
325 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
326 ]]*)