comparison lab4/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 (* Alias analysis and VAR parameters *)
2
3 var a,b,c,d: integer;
4
5 proc p1(var a: integer; b: integer; var d: integer): integer;
6 var c: integer;
7 begin
8 c :=b+a;
9 d :=b+1;
10 a :=a-b;
11 return (a+d)*b
12 end;
13
14 begin
15 a:=5; b:=2; c:=3; d:=1;
16 b := p1(b,d,a) + 1;
17 print_string("A="); print_num(a);
18 print_string(" B="); print_num(b);
19 print_string(" C="); print_num(c);
20 print_string(" D="); print_num(d);
21 newline()
22 end.
23
24 (*<<
25 A=2 B=4 C=3 D=1
26 >>*)
27
28 (*[[
29 @ picoPascal compiler output
30 .include "fixup.s"
31 .global pmain
32
33 @ proc p1(var a: integer; b: integer; var d: integer): integer;
34 .text
35 _p1:
36 mov ip, sp
37 stmfd sp!, {r0-r3}
38 stmfd sp!, {r4-r10, fp, ip, lr}
39 mov fp, sp
40 @ c :=b+a;
41 ldr r5, [fp, #44]
42 ldr r0, [fp, #40]
43 ldr r0, [r0]
44 add r4, r5, r0
45 @ d :=b+1;
46 add r0, r5, #1
47 ldr r1, [fp, #48]
48 str r0, [r1]
49 @ a :=a-b;
50 ldr r5, [fp, #40]
51 ldr r0, [r5]
52 ldr r1, [fp, #44]
53 sub r0, r0, r1
54 str r0, [r5]
55 @ return (a+d)*b
56 ldr r0, [fp, #40]
57 ldr r0, [r0]
58 ldr r1, [fp, #48]
59 ldr r1, [r1]
60 add r0, r0, r1
61 ldr r1, [fp, #44]
62 mul r0, r0, r1
63 ldmfd fp, {r4-r10, fp, sp, pc}
64 .ltorg
65
66 pmain:
67 mov ip, sp
68 stmfd sp!, {r4-r10, fp, ip, lr}
69 mov fp, sp
70 @ a:=5; b:=2; c:=3; d:=1;
71 set r4, _a
72 mov r0, #5
73 str r0, [r4]
74 set r5, _b
75 mov r0, #2
76 str r0, [r5]
77 mov r0, #3
78 set r1, _c
79 str r0, [r1]
80 mov r6, #1
81 set r0, _d
82 str r6, [r0]
83 @ b := p1(b,d,a) + 1;
84 mov r2, r4
85 mov r1, r6
86 mov r0, r5
87 bl _p1
88 add r0, r0, #1
89 set r1, _b
90 str r0, [r1]
91 @ print_string("A="); print_num(a);
92 mov r1, #2
93 set r0, g1
94 bl print_string
95 set r0, _a
96 ldr r0, [r0]
97 bl print_num
98 @ print_string(" B="); print_num(b);
99 mov r1, #3
100 set r0, g2
101 bl print_string
102 set r0, _b
103 ldr r0, [r0]
104 bl print_num
105 @ print_string(" C="); print_num(c);
106 mov r1, #3
107 set r0, g3
108 bl print_string
109 set r0, _c
110 ldr r0, [r0]
111 bl print_num
112 @ print_string(" D="); print_num(d);
113 mov r1, #3
114 set r0, g4
115 bl print_string
116 set r0, _d
117 ldr r0, [r0]
118 bl print_num
119 @ newline()
120 bl newline
121 ldmfd fp, {r4-r10, fp, sp, pc}
122 .ltorg
123
124 .comm _a, 4, 4
125 .comm _b, 4, 4
126 .comm _c, 4, 4
127 .comm _d, 4, 4
128 .data
129 g1:
130 .byte 65, 61
131 .byte 0
132 g2:
133 .byte 32, 66, 61
134 .byte 0
135 g3:
136 .byte 32, 67, 61
137 .byte 0
138 g4:
139 .byte 32, 68, 61
140 .byte 0
141 @ End
142 ]]*)