annotate lab4/test/baz.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 (* Assigning to a global variable from a procedure *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 var x: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 proc baz(u: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 x := u;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 return x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 print_num(baz(37)); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 print_num(x); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 @ picoPascal compiler output
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 .include "fixup.s"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 .global pmain
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 @ proc baz(u: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 _baz:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 @ x := u;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 ldr r4, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 set r0, _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 str r4, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 @ return x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 mov r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 @ print_num(baz(37)); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 mov r0, #37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 bl _baz
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 @ print_num(x); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 set r0, _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 ldr r0, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 .comm _x, 4, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 ]]*)