annotate lab4/test/allregs.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 (* Expressions with high register demand *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 proc foo(a, b, c, d: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 return
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 (a-b)*(a-c)*(a-d)*(b-c)*(b-d)*(c-d)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 +
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 (a-c)*(a-d)*(b-c)*(b-d)*(c-d)*(a-b)
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 proc baz(n: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 return (n-1)*(n-1)
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 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 print_num(foo(1,2,3,4)); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 print_num(baz(10)); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 end.
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 24
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 81
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 foo(a, b, c, d: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 _foo:
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-r3}
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 @ return
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 ldr r4, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 ldr r5, [fp, #44]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 sub r6, r4, r5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 ldr r7, [fp, #48]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 sub r8, r4, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 ldr r9, [fp, #52]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 sub r4, r4, r9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 sub r0, r5, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 sub r5, r5, r9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 sub r7, r7, r9
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 mul r1, r6, r8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 mul r1, r1, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 mul r1, r1, r0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 mul r1, r1, r5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 mul r1, r1, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 mul r2, r8, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 mul r0, r2, r0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 mul r0, r0, r5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 mul r0, r0, r7
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 mul r0, r0, r6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 add r0, r1, r0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 @ proc baz(n: integer): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 _baz:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 stmfd sp!, {r0-r1}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 @ return (n-1)*(n-1)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 ldr r0, [fp, #40]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 sub r4, r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 mul r0, r4, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
78 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
79 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
80 @ print_num(foo(1,2,3,4)); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
81 mov r3, #4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
82 mov r2, #3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
83 mov r1, #2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
84 mov r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
85 bl _foo
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
86 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
87 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
88 @ print_num(baz(10)); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
89 mov r0, #10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
90 bl _baz
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
91 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
92 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
93 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
94 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
95
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
96 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
97 ]]*)