annotate ppc/test/funny.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 var a,b,c,d: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 proc p1(var a: integer; b: integer; var d: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 var c: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 c :=b+a;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 d :=b+1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 a :=a-b;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 return (a+d)*b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 a:=5; b:=2; c:=3; d:=1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 b := p1(b,d,a) + 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 print_string("A="); print_num(a);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 print_string(" B="); print_num(b);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 print_string(" C="); print_num(c);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 print_string(" D="); print_num(d);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 A=2 B=4 C=3 D=1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 PROC _p1 4 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 ! c :=b+a;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 LOADW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 STLW -4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 ! d :=b+1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 LDLW 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 STOREW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 ! a :=a-b;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 LOADW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 STOREW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 ! return (a+d)*b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 LDLW 16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 LOADW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 LDLW 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 LOADW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 LDLW 20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 TIMES
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 RETURNW
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 ! a:=5; b:=2; c:=3; d:=1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 CONST 5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 STGW _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 STGW _b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 STGW _c
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 STGW _d
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 ! b := p1(b,d,a) + 1;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 GLOBAL _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 LDGW _d
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 GLOBAL _b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 GLOBAL _p1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 PCALLW 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 CONST 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 PLUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 STGW _b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 ! print_string("A="); print_num(a);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 CONST 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 GLOBAL g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 LDGW _a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 ! print_string(" B="); print_num(b);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 GLOBAL g2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
98 LDGW _b
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
99 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
100 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
101 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
102 ! print_string(" C="); print_num(c);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
103 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
104 GLOBAL g3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
105 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
106 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
107 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
108 LDGW _c
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
109 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
110 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
111 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
112 ! print_string(" D="); print_num(d);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
113 CONST 3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
114 GLOBAL g4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
115 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
116 GLOBAL lib.print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
117 PCALL 2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
118 LDGW _d
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
119 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
120 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
121 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
122 ! newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
123 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
124 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
125 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
126 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
127 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
128
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
129 GLOVAR _a 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
130 GLOVAR _b 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
131 GLOVAR _c 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
132 GLOVAR _d 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
133 ! String "A="
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
134 DEFINE g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
135 STRING 413D00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
136
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
137 ! String " B="
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
138 DEFINE g2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
139 STRING 20423D00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
140
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
141 ! String " C="
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
142 DEFINE g3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
143 STRING 20433D00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
144
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
145 ! String " D="
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
146 DEFINE g4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
147 STRING 20443D00
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
148
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
149 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
150 ]]*)