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