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