annotate ppc/test/funny.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 var a,b,c,d: integer;
mike@0 2
mike@0 3 proc p1(var a: integer; b: integer; var d: integer): integer;
mike@0 4 var c: integer;
mike@0 5 begin
mike@0 6 c :=b+a;
mike@0 7 d :=b+1;
mike@0 8 a :=a-b;
mike@0 9 return (a+d)*b
mike@0 10 end;
mike@0 11
mike@0 12 begin
mike@0 13 a:=5; b:=2; c:=3; d:=1;
mike@0 14 b := p1(b,d,a) + 1;
mike@0 15 print_string("A="); print_num(a);
mike@0 16 print_string(" B="); print_num(b);
mike@0 17 print_string(" C="); print_num(c);
mike@0 18 print_string(" D="); print_num(d);
mike@0 19 newline()
mike@0 20 end.
mike@0 21
mike@0 22 (*<<
mike@0 23 A=2 B=4 C=3 D=1
mike@0 24 >>*)
mike@0 25
mike@0 26 (*[[
mike@0 27 MODULE Main 0 0
mike@0 28 IMPORT Lib 0
mike@0 29 ENDHDR
mike@0 30
mike@0 31 PROC _p1 4 0 0
mike@0 32 ! c :=b+a;
mike@0 33 LDLW 20
mike@0 34 LDLW 16
mike@0 35 LOADW
mike@0 36 PLUS
mike@0 37 STLW -4
mike@0 38 ! d :=b+1;
mike@0 39 LDLW 20
mike@0 40 CONST 1
mike@0 41 PLUS
mike@0 42 LDLW 24
mike@0 43 STOREW
mike@0 44 ! a :=a-b;
mike@0 45 LDLW 16
mike@0 46 LOADW
mike@0 47 LDLW 20
mike@0 48 MINUS
mike@0 49 LDLW 16
mike@0 50 STOREW
mike@0 51 ! return (a+d)*b
mike@0 52 LDLW 16
mike@0 53 LOADW
mike@0 54 LDLW 24
mike@0 55 LOADW
mike@0 56 PLUS
mike@0 57 LDLW 20
mike@0 58 TIMES
mike@0 59 RETURNW
mike@0 60 END
mike@0 61
mike@0 62 PROC MAIN 0 0 0
mike@0 63 ! a:=5; b:=2; c:=3; d:=1;
mike@0 64 CONST 5
mike@0 65 STGW _a
mike@0 66 CONST 2
mike@0 67 STGW _b
mike@0 68 CONST 3
mike@0 69 STGW _c
mike@0 70 CONST 1
mike@0 71 STGW _d
mike@0 72 ! b := p1(b,d,a) + 1;
mike@0 73 GLOBAL _a
mike@0 74 LDGW _d
mike@0 75 GLOBAL _b
mike@0 76 CONST 0
mike@0 77 GLOBAL _p1
mike@0 78 PCALLW 3
mike@0 79 CONST 1
mike@0 80 PLUS
mike@0 81 STGW _b
mike@0 82 ! print_string("A="); print_num(a);
mike@0 83 CONST 2
mike@0 84 GLOBAL g1
mike@0 85 CONST 0
mike@0 86 GLOBAL lib.print_string
mike@0 87 PCALL 2
mike@0 88 LDGW _a
mike@0 89 CONST 0
mike@0 90 GLOBAL lib.print_num
mike@0 91 PCALL 1
mike@0 92 ! print_string(" B="); print_num(b);
mike@0 93 CONST 3
mike@0 94 GLOBAL g2
mike@0 95 CONST 0
mike@0 96 GLOBAL lib.print_string
mike@0 97 PCALL 2
mike@0 98 LDGW _b
mike@0 99 CONST 0
mike@0 100 GLOBAL lib.print_num
mike@0 101 PCALL 1
mike@0 102 ! print_string(" C="); print_num(c);
mike@0 103 CONST 3
mike@0 104 GLOBAL g3
mike@0 105 CONST 0
mike@0 106 GLOBAL lib.print_string
mike@0 107 PCALL 2
mike@0 108 LDGW _c
mike@0 109 CONST 0
mike@0 110 GLOBAL lib.print_num
mike@0 111 PCALL 1
mike@0 112 ! print_string(" D="); print_num(d);
mike@0 113 CONST 3
mike@0 114 GLOBAL g4
mike@0 115 CONST 0
mike@0 116 GLOBAL lib.print_string
mike@0 117 PCALL 2
mike@0 118 LDGW _d
mike@0 119 CONST 0
mike@0 120 GLOBAL lib.print_num
mike@0 121 PCALL 1
mike@0 122 ! newline()
mike@0 123 CONST 0
mike@0 124 GLOBAL lib.newline
mike@0 125 PCALL 0
mike@0 126 RETURN
mike@0 127 END
mike@0 128
mike@0 129 GLOVAR _a 4
mike@0 130 GLOVAR _b 4
mike@0 131 GLOVAR _c 4
mike@0 132 GLOVAR _d 4
mike@0 133 ! String "A="
mike@0 134 DEFINE g1
mike@0 135 STRING 413D00
mike@0 136
mike@0 137 ! String " B="
mike@0 138 DEFINE g2
mike@0 139 STRING 20423D00
mike@0 140
mike@0 141 ! String " C="
mike@0 142 DEFINE g3
mike@0 143 STRING 20433D00
mike@0 144
mike@0 145 ! String " D="
mike@0 146 DEFINE g4
mike@0 147 STRING 20443D00
mike@0 148
mike@0 149 ! End
mike@0 150 ]]*)