comparison ppc/test/strcopy.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 (* strcopy.p *)
2
3 const in = "Hello, world!*";
4
5 var out: array 128 of char; i: integer;
6
7 begin
8 i := 0;
9 while in[i] <> '*' do
10 out[i] := in[i];
11 i := i + 1
12 end;
13 out[i] := chr(0);
14 print_string(out); newline()
15 end.
16
17 (*<<
18 Hello, world!
19 >>*)
20
21 (*[[
22 MODULE Main 0 0
23 IMPORT Lib 0
24 ENDHDR
25
26 PROC MAIN 0 0 0
27 ! i := 0;
28 CONST 0
29 STGW _i
30 ! while in[i] <> '*' do
31 JUMP L3
32 LABEL L2
33 ! out[i] := in[i];
34 GLOBAL g1
35 LDGW _i
36 LDIC
37 GLOBAL _out
38 LDGW _i
39 STIC
40 ! i := i + 1
41 LDGW _i
42 CONST 1
43 PLUS
44 STGW _i
45 LABEL L3
46 GLOBAL g1
47 LDGW _i
48 LDIC
49 CONST 42
50 JNEQ L2
51 ! out[i] := chr(0);
52 CONST 0
53 GLOBAL _out
54 LDGW _i
55 STIC
56 ! print_string(out); newline()
57 CONST 128
58 GLOBAL _out
59 CONST 0
60 GLOBAL lib.print_string
61 PCALL 2
62 CONST 0
63 GLOBAL lib.newline
64 PCALL 0
65 RETURN
66 END
67
68 GLOVAR _out 128
69 GLOVAR _i 4
70 ! String "Hello, world!*"
71 DEFINE g1
72 STRING 48656C6C6F2C20776F726C64212A00
73
74 ! End
75 ]]*)