### comparison lab4/test/mob.p @ 0:bfdcc3820b32

Basis
author Mike Spivey Thu, 05 Oct 2017 08:04:15 +0100
comparison
equal inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* Knuth's "Man or Boy" test *)
2
3 proc A(k: integer; proc x1(): integer; proc x2(): integer;
4 proc x3(): integer; proc x4(): integer; proc x5(): integer): integer;
5 proc B(): integer;
6 begin
7 k := k-1;
8 return A(k, B, x1, x2, x3, x4)
9 end;
10 begin
11 if k <= 0 then return x4() + x5() else return B() end
12 end;
13
14 proc One(): integer; begin return 1 end;
15 proc MOne(): integer; begin return -1 end;
16 proc Zero(): integer; begin return 0 end;
17
18 begin
19 print_num(A(10, One, MOne, MOne, One, Zero)); newline()
20 end.
21
22 (*<<
23 -67
24 >>*)
25
26 (*[[
27 @ picoPascal compiler output
28 .include "fixup.s"
29 .global pmain
30
31 @ proc A(k: integer; proc x1(): integer; proc x2(): integer;
32 .text
33 _A:
34 mov ip, sp
35 stmfd sp!, {r0-r3}
36 stmfd sp!, {r4-r10, fp, ip, lr}
37 mov fp, sp
38 @ if k <= 0 then return x4() + x5() else return B() end
39 ldr r0, [fp, #40]
40 cmp r0, #0
41 bgt .L3
42 ldr r10, [fp, #72]
43 ldr r0, [fp, #68]
44 blx r0
45 ldr r10, [fp, #80]
46 mov r4, r0
47 ldr r0, [fp, #76]
48 blx r0
50 b .L1
51 .L3:
52 mov r10, fp
53 bl _B
54 .L1:
55 ldmfd fp, {r4-r10, fp, sp, pc}
56 .ltorg
57
58 @ proc B(): integer;
59 _B:
60 mov ip, sp
61 stmfd sp!, {r4-r10, fp, ip, lr}
62 mov fp, sp
63 sub sp, sp, #32
64 @ k := k-1;
65 ldr r0, [fp, #24]
67 ldr r0, [r4]
68 sub r0, r0, #1
69 str r0, [r4]
70 @ return A(k, B, x1, x2, x3, x4)
71 ldr r4, [fp, #24]
72 ldr r0, [r4, #72]
73 str r0, [sp, #24]
74 ldr r0, [r4, #68]
75 str r0, [sp, #20]
76 ldr r0, [r4, #64]
77 str r0, [sp, #16]
78 ldr r0, [r4, #60]
79 str r0, [sp, #12]
80 ldr r0, [r4, #56]
81 str r0, [sp, #8]
82 ldr r0, [r4, #52]
83 str r0, [sp, #4]
84 ldr r0, [r4, #48]
85 str r0, [sp]
86 ldr r3, [r4, #44]
87 mov r2, r4
88 set r1, _B
89 ldr r0, [r4, #40]
90 bl _A
91 ldmfd fp, {r4-r10, fp, sp, pc}
92 .ltorg
93
94 @ proc One(): integer; begin return 1 end;
95 _One:
96 mov ip, sp
97 stmfd sp!, {r4-r10, fp, ip, lr}
98 mov fp, sp
99 @ proc One(): integer; begin return 1 end;
100 mov r0, #1
101 ldmfd fp, {r4-r10, fp, sp, pc}
102 .ltorg
103
104 @ proc MOne(): integer; begin return -1 end;
105 _MOne:
106 mov ip, sp
107 stmfd sp!, {r4-r10, fp, ip, lr}
108 mov fp, sp
109 @ proc MOne(): integer; begin return -1 end;
110 mov r0, #-1
111 ldmfd fp, {r4-r10, fp, sp, pc}
112 .ltorg
113
114 @ proc Zero(): integer; begin return 0 end;
115 _Zero:
116 mov ip, sp
117 stmfd sp!, {r4-r10, fp, ip, lr}
118 mov fp, sp
119 @ proc Zero(): integer; begin return 0 end;
120 mov r0, #0
121 ldmfd fp, {r4-r10, fp, sp, pc}
122 .ltorg
123
124 pmain:
125 mov ip, sp
126 stmfd sp!, {r4-r10, fp, ip, lr}
127 mov fp, sp
128 sub sp, sp, #32
129 @ print_num(A(10, One, MOne, MOne, One, Zero)); newline()
130 set r4, _One
131 set r5, _MOne
132 mov r0, #0
133 str r0, [sp, #24]
134 set r0, _Zero
135 str r0, [sp, #20]
136 mov r0, #0
137 str r0, [sp, #16]
138 str r4, [sp, #12]
139 mov r0, #0
140 str r0, [sp, #8]
141 str r5, [sp, #4]
142 mov r0, #0
143 str r0, [sp]
144 mov r3, r5
145 mov r2, #0
146 mov r1, r4
147 mov r0, #10
148 bl _A
149 bl print_num
150 bl newline
151 ldmfd fp, {r4-r10, fp, sp, pc}
152 .ltorg
153
154 @ End
155 ]]*)