comparison lab4/test/varparam.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 (* Access to var parameters from nested procedures *)
2
3 proc one(var x: integer);
4 proc two(); begin x := x+1 end;
5 begin
6 two()
7 end;
8
9 proc three();
10 var y: integer;
11 begin
12 y := 36;
13 one(y);
14 print_num(y);
15 newline()
16 end;
17
18 begin
19 three()
20 end.
21
22 (*<<
23 37
24 >>*)
25
26 (*[[
27 @ picoPascal compiler output
28 .include "fixup.s"
29 .global pmain
30
31 @ proc one(var x: integer);
32 .text
33 _one:
34 mov ip, sp
35 stmfd sp!, {r0-r1}
36 stmfd sp!, {r4-r10, fp, ip, lr}
37 mov fp, sp
38 @ two()
39 mov r10, fp
40 bl _two
41 ldmfd fp, {r4-r10, fp, sp, pc}
42 .ltorg
43
44 @ proc two(); begin x := x+1 end;
45 _two:
46 mov ip, sp
47 stmfd sp!, {r4-r10, fp, ip, lr}
48 mov fp, sp
49 @ proc two(); begin x := x+1 end;
50 ldr r0, [fp, #24]
51 ldr r4, [r0, #40]
52 ldr r0, [r4]
53 add r0, r0, #1
54 str r0, [r4]
55 ldmfd fp, {r4-r10, fp, sp, pc}
56 .ltorg
57
58 @ proc three();
59 _three:
60 mov ip, sp
61 stmfd sp!, {r4-r10, fp, ip, lr}
62 mov fp, sp
63 sub sp, sp, #8
64 @ y := 36;
65 mov r0, #36
66 str r0, [fp, #-4]
67 @ one(y);
68 add r0, fp, #-4
69 bl _one
70 @ print_num(y);
71 ldr r0, [fp, #-4]
72 bl print_num
73 @ newline()
74 bl newline
75 ldmfd fp, {r4-r10, fp, sp, pc}
76 .ltorg
77
78 pmain:
79 mov ip, sp
80 stmfd sp!, {r4-r10, fp, ip, lr}
81 mov fp, sp
82 @ three()
83 bl _three
84 ldmfd fp, {r4-r10, fp, sp, pc}
85 .ltorg
86
87 @ End
88 ]]*)