annotate lab4/test/funny.p @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* Alias analysis and VAR parameters *)
mike@0 2
mike@0 3 var a,b,c,d: integer;
mike@0 4
mike@0 5 proc p1(var a: integer; b: integer; var d: integer): integer;
mike@0 6 var c: integer;
mike@0 7 begin
mike@0 8 c :=b+a;
mike@0 9 d :=b+1;
mike@0 10 a :=a-b;
mike@0 11 return (a+d)*b
mike@0 12 end;
mike@0 13
mike@0 14 begin
mike@0 15 a:=5; b:=2; c:=3; d:=1;
mike@0 16 b := p1(b,d,a) + 1;
mike@0 17 print_string("A="); print_num(a);
mike@0 18 print_string(" B="); print_num(b);
mike@0 19 print_string(" C="); print_num(c);
mike@0 20 print_string(" D="); print_num(d);
mike@0 21 newline()
mike@0 22 end.
mike@0 23
mike@0 24 (*<<
mike@0 25 A=2 B=4 C=3 D=1
mike@0 26 >>*)
mike@0 27
mike@0 28 (*[[
mike@0 29 @ picoPascal compiler output
mike@0 30 .include "fixup.s"
mike@0 31 .global pmain
mike@0 32
mike@0 33 @ proc p1(var a: integer; b: integer; var d: integer): integer;
mike@0 34 .text
mike@0 35 _p1:
mike@0 36 mov ip, sp
mike@0 37 stmfd sp!, {r0-r3}
mike@0 38 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 39 mov fp, sp
mike@0 40 @ c :=b+a;
mike@0 41 ldr r5, [fp, #44]
mike@0 42 ldr r0, [fp, #40]
mike@0 43 ldr r0, [r0]
mike@0 44 add r4, r5, r0
mike@0 45 @ d :=b+1;
mike@0 46 add r0, r5, #1
mike@0 47 ldr r1, [fp, #48]
mike@0 48 str r0, [r1]
mike@0 49 @ a :=a-b;
mike@0 50 ldr r5, [fp, #40]
mike@0 51 ldr r0, [r5]
mike@0 52 ldr r1, [fp, #44]
mike@0 53 sub r0, r0, r1
mike@0 54 str r0, [r5]
mike@0 55 @ return (a+d)*b
mike@0 56 ldr r0, [fp, #40]
mike@0 57 ldr r0, [r0]
mike@0 58 ldr r1, [fp, #48]
mike@0 59 ldr r1, [r1]
mike@0 60 add r0, r0, r1
mike@0 61 ldr r1, [fp, #44]
mike@0 62 mul r0, r0, r1
mike@0 63 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 64 .ltorg
mike@0 65
mike@0 66 pmain:
mike@0 67 mov ip, sp
mike@0 68 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 69 mov fp, sp
mike@0 70 @ a:=5; b:=2; c:=3; d:=1;
mike@0 71 set r4, _a
mike@0 72 mov r0, #5
mike@0 73 str r0, [r4]
mike@0 74 set r5, _b
mike@0 75 mov r0, #2
mike@0 76 str r0, [r5]
mike@0 77 mov r0, #3
mike@0 78 set r1, _c
mike@0 79 str r0, [r1]
mike@0 80 mov r6, #1
mike@0 81 set r0, _d
mike@0 82 str r6, [r0]
mike@0 83 @ b := p1(b,d,a) + 1;
mike@0 84 mov r2, r4
mike@0 85 mov r1, r6
mike@0 86 mov r0, r5
mike@0 87 bl _p1
mike@0 88 add r0, r0, #1
mike@0 89 set r1, _b
mike@0 90 str r0, [r1]
mike@0 91 @ print_string("A="); print_num(a);
mike@0 92 mov r1, #2
mike@0 93 set r0, g1
mike@0 94 bl print_string
mike@0 95 set r0, _a
mike@0 96 ldr r0, [r0]
mike@0 97 bl print_num
mike@0 98 @ print_string(" B="); print_num(b);
mike@0 99 mov r1, #3
mike@0 100 set r0, g2
mike@0 101 bl print_string
mike@0 102 set r0, _b
mike@0 103 ldr r0, [r0]
mike@0 104 bl print_num
mike@0 105 @ print_string(" C="); print_num(c);
mike@0 106 mov r1, #3
mike@0 107 set r0, g3
mike@0 108 bl print_string
mike@0 109 set r0, _c
mike@0 110 ldr r0, [r0]
mike@0 111 bl print_num
mike@0 112 @ print_string(" D="); print_num(d);
mike@0 113 mov r1, #3
mike@0 114 set r0, g4
mike@0 115 bl print_string
mike@0 116 set r0, _d
mike@0 117 ldr r0, [r0]
mike@0 118 bl print_num
mike@0 119 @ newline()
mike@0 120 bl newline
mike@0 121 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 122 .ltorg
mike@0 123
mike@0 124 .comm _a, 4, 4
mike@0 125 .comm _b, 4, 4
mike@0 126 .comm _c, 4, 4
mike@0 127 .comm _d, 4, 4
mike@0 128 .data
mike@0 129 g1:
mike@0 130 .byte 65, 61
mike@0 131 .byte 0
mike@0 132 g2:
mike@0 133 .byte 32, 66, 61
mike@0 134 .byte 0
mike@0 135 g3:
mike@0 136 .byte 32, 67, 61
mike@0 137 .byte 0
mike@0 138 g4:
mike@0 139 .byte 32, 68, 61
mike@0 140 .byte 0
mike@0 141 @ End
mike@0 142 ]]*)