comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* Expressions with high register demand *)
2
3 proc foo(a, b, c, d: integer): integer;
4 begin
5 return
6 (a-b)*(a-c)*(a-d)*(b-c)*(b-d)*(c-d)
7 +
8 (a-c)*(a-d)*(b-c)*(b-d)*(c-d)*(a-b)
9 end;
10
11 proc baz(n: integer): integer;
12 begin
13 return (n-1)*(n-1)
14 end;
15
16 begin
17 print_num(foo(1,2,3,4)); newline();
18 print_num(baz(10)); newline()
19 end.
20
21 (*<<
22 24
23 81
24 >>*)
25
26 (*[[
27 @ picoPascal compiler output
28 .include "fixup.s"
29 .global pmain
30
31 @ proc foo(a, b, c, d: integer): integer;
32 .text
33 _foo:
34 mov ip, sp
35 stmfd sp!, {r0-r3}
36 stmfd sp!, {r4-r10, fp, ip, lr}
37 mov fp, sp
38 @ return
39 ldr r4, [fp, #40]
40 ldr r5, [fp, #44]
41 sub r6, r4, r5
42 ldr r7, [fp, #48]
43 sub r8, r4, r7
44 ldr r9, [fp, #52]
45 sub r4, r4, r9
46 sub r0, r5, r7
47 sub r5, r5, r9
48 sub r7, r7, r9
49 mul r1, r6, r8
50 mul r1, r1, r4
51 mul r1, r1, r0
52 mul r1, r1, r5
53 mul r1, r1, r7
54 mul r2, r8, r4
55 mul r0, r2, r0
56 mul r0, r0, r5
57 mul r0, r0, r7
58 mul r0, r0, r6
59 add r0, r1, r0
60 ldmfd fp, {r4-r10, fp, sp, pc}
61 .ltorg
62
63 @ proc baz(n: integer): integer;
64 _baz:
65 mov ip, sp
66 stmfd sp!, {r0-r1}
67 stmfd sp!, {r4-r10, fp, ip, lr}
68 mov fp, sp
69 @ return (n-1)*(n-1)
70 ldr r0, [fp, #40]
71 sub r4, r0, #1
72 mul r0, r4, r4
73 ldmfd fp, {r4-r10, fp, sp, pc}
74 .ltorg
75
76 pmain:
77 mov ip, sp
78 stmfd sp!, {r4-r10, fp, ip, lr}
79 mov fp, sp
80 @ print_num(foo(1,2,3,4)); newline();
81 mov r3, #4
82 mov r2, #3
83 mov r1, #2
84 mov r0, #1
85 bl _foo
86 bl print_num
87 bl newline
88 @ print_num(baz(10)); newline()
89 mov r0, #10
90 bl _baz
91 bl print_num
92 bl newline
93 ldmfd fp, {r4-r10, fp, sp, pc}
94 .ltorg
95
96 @ End
97 ]]*)