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