annotate ppc/test/strcopy.p @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* strcopy.p *)
mike@0 2
mike@0 3 const in = "Hello, world!*";
mike@0 4
mike@0 5 var out: array 128 of char; i: integer;
mike@0 6
mike@0 7 begin
mike@0 8 i := 0;
mike@0 9 while in[i] <> '*' do
mike@0 10 out[i] := in[i];
mike@0 11 i := i + 1
mike@0 12 end;
mike@0 13 out[i] := chr(0);
mike@0 14 print_string(out); newline()
mike@0 15 end.
mike@0 16
mike@0 17 (*<<
mike@0 18 Hello, world!
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;
mike@0 28 CONST 0
mike@0 29 STGW _i
mike@0 30 ! while in[i] <> '*' do
mike@0 31 JUMP L3
mike@0 32 LABEL L2
mike@0 33 ! out[i] := in[i];
mike@0 34 GLOBAL g1
mike@0 35 LDGW _i
mike@0 36 LDIC
mike@0 37 GLOBAL _out
mike@0 38 LDGW _i
mike@0 39 STIC
mike@0 40 ! i := i + 1
mike@0 41 LDGW _i
mike@0 42 CONST 1
mike@0 43 PLUS
mike@0 44 STGW _i
mike@0 45 LABEL L3
mike@0 46 GLOBAL g1
mike@0 47 LDGW _i
mike@0 48 LDIC
mike@0 49 CONST 42
mike@0 50 JNEQ L2
mike@0 51 ! out[i] := chr(0);
mike@0 52 CONST 0
mike@0 53 GLOBAL _out
mike@0 54 LDGW _i
mike@0 55 STIC
mike@0 56 ! print_string(out); newline()
mike@0 57 CONST 128
mike@0 58 GLOBAL _out
mike@0 59 CONST 0
mike@0 60 GLOBAL lib.print_string
mike@0 61 PCALL 2
mike@0 62 CONST 0
mike@0 63 GLOBAL lib.newline
mike@0 64 PCALL 0
mike@0 65 RETURN
mike@0 66 END
mike@0 67
mike@0 68 GLOVAR _out 128
mike@0 69 GLOVAR _i 4
mike@0 70 ! String "Hello, world!*"
mike@0 71 DEFINE g1
mike@0 72 STRING 48656C6C6F2C20776F726C64212A00
mike@0 73
mike@0 74 ! End
mike@0 75 ]]*)