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