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