annotate lab4/test/array.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 (* Local and global arrays *)
mike@0 2
mike@0 3 var i: integer;
mike@0 4
mike@0 5 var a: array 10 of integer;
mike@0 6
mike@0 7 proc foo();
mike@0 8 var j: integer;
mike@0 9 var b : array 10 of integer;
mike@0 10 begin
mike@0 11 print_string("foo"); newline();
mike@0 12 j := 2; b[0] := 1; b[1] := 1;
mike@0 13 while 10 > j do
mike@0 14 b[j] := b[j-2] + b[j-1];
mike@0 15 print_char(' '); print_num(b[j]);
mike@0 16 j := 1+j
mike@0 17 end;
mike@0 18 newline();
mike@0 19 end;
mike@0 20
mike@0 21 begin
mike@0 22 print_string("baz"); newline();
mike@0 23 i := 2; a[0] := 1; a[1] := 1;
mike@0 24 while i < 10 do
mike@0 25 a[i] := a[i-2] + a[i-1];
mike@0 26 print_char(' '); print_num(a[i]);
mike@0 27 i := i+1
mike@0 28 end;
mike@0 29 newline();
mike@0 30 foo()
mike@0 31 end.
mike@0 32
mike@0 33 (*<<
mike@0 34 baz
mike@0 35 2 3 5 8 13 21 34 55
mike@0 36 foo
mike@0 37 2 3 5 8 13 21 34 55
mike@0 38 >>*)
mike@0 39
mike@0 40 (*[[
mike@0 41 @ picoPascal compiler output
mike@0 42 .include "fixup.s"
mike@0 43 .global pmain
mike@0 44
mike@0 45 @ proc foo();
mike@0 46 .text
mike@0 47 _foo:
mike@0 48 mov ip, sp
mike@0 49 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 50 mov fp, sp
mike@0 51 sub sp, sp, #40
mike@0 52 @ print_string("foo"); newline();
mike@0 53 mov r1, #3
mike@0 54 set r0, g1
mike@0 55 bl print_string
mike@0 56 bl newline
mike@0 57 @ j := 2; b[0] := 1; b[1] := 1;
mike@0 58 mov r4, #2
mike@0 59 mov r0, #1
mike@0 60 str r0, [fp, #-40]
mike@0 61 mov r0, #1
mike@0 62 str r0, [fp, #-36]
mike@0 63 .L4:
mike@0 64 @ while 10 > j do
mike@0 65 cmp r4, #10
mike@0 66 bge .L6
mike@0 67 @ b[j] := b[j-2] + b[j-1];
mike@0 68 add r0, fp, #-40
mike@0 69 lsl r1, r4, #2
mike@0 70 add r5, r0, r1
mike@0 71 ldr r0, [r5, #-8]
mike@0 72 ldr r1, [r5, #-4]
mike@0 73 add r0, r0, r1
mike@0 74 str r0, [r5]
mike@0 75 @ print_char(' '); print_num(b[j]);
mike@0 76 mov r0, #32
mike@0 77 bl print_char
mike@0 78 add r0, fp, #-40
mike@0 79 lsl r1, r4, #2
mike@0 80 add r0, r0, r1
mike@0 81 ldr r0, [r0]
mike@0 82 bl print_num
mike@0 83 @ j := 1+j
mike@0 84 add r4, r4, #1
mike@0 85 b .L4
mike@0 86 .L6:
mike@0 87 @ newline();
mike@0 88 bl newline
mike@0 89 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 90 .ltorg
mike@0 91
mike@0 92 pmain:
mike@0 93 mov ip, sp
mike@0 94 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 95 mov fp, sp
mike@0 96 @ print_string("baz"); newline();
mike@0 97 mov r1, #3
mike@0 98 set r0, g2
mike@0 99 bl print_string
mike@0 100 bl newline
mike@0 101 @ i := 2; a[0] := 1; a[1] := 1;
mike@0 102 mov r0, #2
mike@0 103 set r1, _i
mike@0 104 str r0, [r1]
mike@0 105 set r4, _a
mike@0 106 mov r0, #1
mike@0 107 str r0, [r4]
mike@0 108 mov r0, #1
mike@0 109 str r0, [r4, #4]
mike@0 110 .L8:
mike@0 111 @ while i < 10 do
mike@0 112 set r0, _i
mike@0 113 ldr r4, [r0]
mike@0 114 cmp r4, #10
mike@0 115 bge .L10
mike@0 116 @ a[i] := a[i-2] + a[i-1];
mike@0 117 set r0, _a
mike@0 118 lsl r1, r4, #2
mike@0 119 add r4, r0, r1
mike@0 120 ldr r0, [r4, #-8]
mike@0 121 ldr r1, [r4, #-4]
mike@0 122 add r0, r0, r1
mike@0 123 str r0, [r4]
mike@0 124 @ print_char(' '); print_num(a[i]);
mike@0 125 mov r0, #32
mike@0 126 bl print_char
mike@0 127 set r0, _a
mike@0 128 set r1, _i
mike@0 129 ldr r1, [r1]
mike@0 130 lsl r1, r1, #2
mike@0 131 add r0, r0, r1
mike@0 132 ldr r0, [r0]
mike@0 133 bl print_num
mike@0 134 @ i := i+1
mike@0 135 set r4, _i
mike@0 136 ldr r0, [r4]
mike@0 137 add r0, r0, #1
mike@0 138 str r0, [r4]
mike@0 139 b .L8
mike@0 140 .L10:
mike@0 141 @ newline();
mike@0 142 bl newline
mike@0 143 @ foo()
mike@0 144 bl _foo
mike@0 145 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 146 .ltorg
mike@0 147
mike@0 148 .comm _i, 4, 4
mike@0 149 .comm _a, 40, 4
mike@0 150 .data
mike@0 151 g1:
mike@0 152 .byte 102, 111, 111
mike@0 153 .byte 0
mike@0 154 g2:
mike@0 155 .byte 98, 97, 122
mike@0 156 .byte 0
mike@0 157 @ End
mike@0 158 ]]*)