annotate ppc/test/array.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 (* array.p *)
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 MODULE Main 0 0
mike@0 42 IMPORT Lib 0
mike@0 43 ENDHDR
mike@0 44
mike@0 45 PROC _foo 44 0 0
mike@0 46 ! print_string("foo"); newline();
mike@0 47 CONST 3
mike@0 48 GLOBAL g1
mike@0 49 CONST 0
mike@0 50 GLOBAL lib.print_string
mike@0 51 PCALL 2
mike@0 52 CONST 0
mike@0 53 GLOBAL lib.newline
mike@0 54 PCALL 0
mike@0 55 ! j := 2; b[0] := 1; b[1] := 1;
mike@0 56 CONST 2
mike@0 57 STLW -4
mike@0 58 CONST 1
mike@0 59 STLW -44
mike@0 60 CONST 1
mike@0 61 STLW -40
mike@0 62 ! while 10 > j do
mike@0 63 JUMP L4
mike@0 64 LABEL L3
mike@0 65 ! b[j] := b[j-2] + b[j-1];
mike@0 66 LOCAL -44
mike@0 67 LDLW -4
mike@0 68 CONST 2
mike@0 69 MINUS
mike@0 70 LDIW
mike@0 71 LOCAL -44
mike@0 72 LDLW -4
mike@0 73 CONST 1
mike@0 74 MINUS
mike@0 75 LDIW
mike@0 76 PLUS
mike@0 77 LOCAL -44
mike@0 78 LDLW -4
mike@0 79 STIW
mike@0 80 ! print_char(' '); print_num(b[j]);
mike@0 81 CONST 32
mike@0 82 CONST 0
mike@0 83 GLOBAL lib.print_char
mike@0 84 PCALL 1
mike@0 85 LOCAL -44
mike@0 86 LDLW -4
mike@0 87 LDIW
mike@0 88 CONST 0
mike@0 89 GLOBAL lib.print_num
mike@0 90 PCALL 1
mike@0 91 ! j := 1+j
mike@0 92 CONST 1
mike@0 93 LDLW -4
mike@0 94 PLUS
mike@0 95 STLW -4
mike@0 96 LABEL L4
mike@0 97 CONST 10
mike@0 98 LDLW -4
mike@0 99 JGT L3
mike@0 100 ! newline();
mike@0 101 CONST 0
mike@0 102 GLOBAL lib.newline
mike@0 103 PCALL 0
mike@0 104 ! end;
mike@0 105 RETURN
mike@0 106 END
mike@0 107
mike@0 108 PROC MAIN 0 0 0
mike@0 109 ! print_string("baz"); newline();
mike@0 110 CONST 3
mike@0 111 GLOBAL g2
mike@0 112 CONST 0
mike@0 113 GLOBAL lib.print_string
mike@0 114 PCALL 2
mike@0 115 CONST 0
mike@0 116 GLOBAL lib.newline
mike@0 117 PCALL 0
mike@0 118 ! i := 2; a[0] := 1; a[1] := 1;
mike@0 119 CONST 2
mike@0 120 STGW _i
mike@0 121 CONST 1
mike@0 122 STGW _a
mike@0 123 CONST 1
mike@0 124 GLOBAL _a
mike@0 125 STNW 4
mike@0 126 ! while i < 10 do
mike@0 127 JUMP L7
mike@0 128 LABEL L6
mike@0 129 ! a[i] := a[i-2] + a[i-1];
mike@0 130 GLOBAL _a
mike@0 131 LDGW _i
mike@0 132 CONST 2
mike@0 133 MINUS
mike@0 134 LDIW
mike@0 135 GLOBAL _a
mike@0 136 LDGW _i
mike@0 137 CONST 1
mike@0 138 MINUS
mike@0 139 LDIW
mike@0 140 PLUS
mike@0 141 GLOBAL _a
mike@0 142 LDGW _i
mike@0 143 STIW
mike@0 144 ! print_char(' '); print_num(a[i]);
mike@0 145 CONST 32
mike@0 146 CONST 0
mike@0 147 GLOBAL lib.print_char
mike@0 148 PCALL 1
mike@0 149 GLOBAL _a
mike@0 150 LDGW _i
mike@0 151 LDIW
mike@0 152 CONST 0
mike@0 153 GLOBAL lib.print_num
mike@0 154 PCALL 1
mike@0 155 ! i := i+1
mike@0 156 LDGW _i
mike@0 157 CONST 1
mike@0 158 PLUS
mike@0 159 STGW _i
mike@0 160 LABEL L7
mike@0 161 LDGW _i
mike@0 162 CONST 10
mike@0 163 JLT L6
mike@0 164 ! newline();
mike@0 165 CONST 0
mike@0 166 GLOBAL lib.newline
mike@0 167 PCALL 0
mike@0 168 ! foo()
mike@0 169 CONST 0
mike@0 170 GLOBAL _foo
mike@0 171 PCALL 0
mike@0 172 RETURN
mike@0 173 END
mike@0 174
mike@0 175 GLOVAR _i 4
mike@0 176 GLOVAR _a 40
mike@0 177 ! String "foo"
mike@0 178 DEFINE g1
mike@0 179 STRING 666F6F00
mike@0 180
mike@0 181 ! String "baz"
mike@0 182 DEFINE g2
mike@0 183 STRING 62617A00
mike@0 184
mike@0 185 ! End
mike@0 186 ]]*)