comparison lab4/test/prob3-3.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 (* From a problem sheet *)
2
3 proc double(x: integer): integer;
4 begin
5 return x + x
6 end;
7
8 proc apply3(proc f(x:integer): integer): integer;
9 begin
10 return f(3)
11 end;
12
13 begin
14 print_num(apply3(double));
15 newline()
16 end.
17
18 (*<<
19 6
20 >>*)
21
22 (*[[
23 @ picoPascal compiler output
24 .include "fixup.s"
25 .global pmain
26
27 @ proc double(x: integer): integer;
28 .text
29 _double:
30 mov ip, sp
31 stmfd sp!, {r0-r1}
32 stmfd sp!, {r4-r10, fp, ip, lr}
33 mov fp, sp
34 @ return x + x
35 ldr r4, [fp, #40]
36 add r0, r4, r4
37 ldmfd fp, {r4-r10, fp, sp, pc}
38 .ltorg
39
40 @ proc apply3(proc f(x:integer): integer): integer;
41 _apply3:
42 mov ip, sp
43 stmfd sp!, {r0-r1}
44 stmfd sp!, {r4-r10, fp, ip, lr}
45 mov fp, sp
46 @ return f(3)
47 mov r0, #3
48 ldr r10, [fp, #44]
49 ldr r1, [fp, #40]
50 blx r1
51 ldmfd fp, {r4-r10, fp, sp, pc}
52 .ltorg
53
54 pmain:
55 mov ip, sp
56 stmfd sp!, {r4-r10, fp, ip, lr}
57 mov fp, sp
58 @ print_num(apply3(double));
59 mov r1, #0
60 set r0, _double
61 bl _apply3
62 bl print_num
63 @ newline()
64 bl newline
65 ldmfd fp, {r4-r10, fp, sp, pc}
66 .ltorg
67
68 @ End
69 ]]*)