annotate ppc/test/search.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 (* search.p *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 const target = "abracadabra";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 var i: integer; found: boolean;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 i := 0; found := false;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 while not found do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 found := target[i] = 'd';
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 i := i + 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 print_num(i);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 newline()
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 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 ! i := 0; found := false;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 STGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 STGC _found
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 ! while not found do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 JUMP L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 LABEL L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 ! found := target[i] = 'd';
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 GLOBAL g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 LDIC
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 CONST 100
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 EQ
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 STGC _found
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 ! i := i + 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 STGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 LABEL L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 LDGC _found
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 JNEQZ L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 JUMP L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 LABEL L4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 ! print_num(i);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 LDGW _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 ! newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 GLOVAR _i 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 GLOVAR _found 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 ! String "abracadabra"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 DEFINE g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 STRING 616272616361646162726100
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 ]]*)