comparison lab4/test/callshare.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 (* Identical function calls are not merged by CSE *)
2
3 var x, y: integer;
4
5 proc f(n: integer): integer;
6 begin x := x + n; return x end;
7
8 begin
9 x := 2;
10 y := f(3) + 1;
11 y := f(3) + 1;
12 print_num(x); newline()
13 end.
14
15 (*<<
16 8
17 >>*)
18
19 (*[[
20 @ picoPascal compiler output
21 .include "fixup.s"
22 .global pmain
23
24 @ proc f(n: integer): integer;
25 .text
26 _f:
27 mov ip, sp
28 stmfd sp!, {r0-r1}
29 stmfd sp!, {r4-r10, fp, ip, lr}
30 mov fp, sp
31 @ begin x := x + n; return x end;
32 set r4, _x
33 ldr r0, [r4]
34 ldr r1, [fp, #40]
35 add r5, r0, r1
36 str r5, [r4]
37 mov r0, r5
38 ldmfd fp, {r4-r10, fp, sp, pc}
39 .ltorg
40
41 pmain:
42 mov ip, sp
43 stmfd sp!, {r4-r10, fp, ip, lr}
44 mov fp, sp
45 @ x := 2;
46 mov r0, #2
47 set r1, _x
48 str r0, [r1]
49 @ y := f(3) + 1;
50 mov r0, #3
51 bl _f
52 add r0, r0, #1
53 set r1, _y
54 str r0, [r1]
55 @ y := f(3) + 1;
56 mov r0, #3
57 bl _f
58 add r0, r0, #1
59 set r1, _y
60 str r0, [r1]
61 @ print_num(x); newline()
62 set r0, _x
63 ldr r0, [r0]
64 bl print_num
65 bl newline
66 ldmfd fp, {r4-r10, fp, sp, pc}
67 .ltorg
68
69 .comm _x, 4, 4
70 .comm _y, 4, 4
71 @ End
72 ]]*)