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