annotate ppc/test/foo.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 (* foo.p *)
mike@0 2
mike@0 3 proc gcd(u, v: integer): integer;
mike@0 4 var x, y: integer;
mike@0 5 begin
mike@0 6 x := u; y := v;
mike@0 7 while x <> y do
mike@0 8 if x < y then
mike@0 9 y := y - x
mike@0 10 else
mike@0 11 x := x - y
mike@0 12 end
mike@0 13 end;
mike@0 14 return x
mike@0 15 end;
mike@0 16
mike@0 17 var z: integer;
mike@0 18 begin
mike@0 19 z := gcd(3*37, 5*37);
mike@0 20 print_string("The final answer is calculated as ");
mike@0 21 print_num(z); newline()
mike@0 22 end.
mike@0 23
mike@0 24 (*<<
mike@0 25 The final answer is calculated as 37
mike@0 26 >>*)
mike@0 27
mike@0 28 (*[[
mike@0 29 MODULE Main 0 0
mike@0 30 IMPORT Lib 0
mike@0 31 ENDHDR
mike@0 32
mike@0 33 PROC _gcd 8 0 0
mike@0 34 ! x := u; y := v;
mike@0 35 LDLW 16
mike@0 36 STLW -4
mike@0 37 LDLW 20
mike@0 38 STLW -8
mike@0 39 ! while x <> y do
mike@0 40 JUMP L3
mike@0 41 LABEL L2
mike@0 42 ! if x < y then
mike@0 43 LDLW -4
mike@0 44 LDLW -8
mike@0 45 JGEQ L6
mike@0 46 ! y := y - x
mike@0 47 LDLW -8
mike@0 48 LDLW -4
mike@0 49 MINUS
mike@0 50 STLW -8
mike@0 51 JUMP L3
mike@0 52 LABEL L6
mike@0 53 ! x := x - y
mike@0 54 LDLW -4
mike@0 55 LDLW -8
mike@0 56 MINUS
mike@0 57 STLW -4
mike@0 58 LABEL L3
mike@0 59 LDLW -4
mike@0 60 LDLW -8
mike@0 61 JNEQ L2
mike@0 62 ! return x
mike@0 63 LDLW -4
mike@0 64 RETURNW
mike@0 65 END
mike@0 66
mike@0 67 PROC MAIN 0 0 0
mike@0 68 ! z := gcd(3*37, 5*37);
mike@0 69 CONST 185
mike@0 70 CONST 111
mike@0 71 CONST 0
mike@0 72 GLOBAL _gcd
mike@0 73 PCALLW 2
mike@0 74 STGW _z
mike@0 75 ! print_string("The final answer is calculated as ");
mike@0 76 CONST 34
mike@0 77 GLOBAL g1
mike@0 78 CONST 0
mike@0 79 GLOBAL lib.print_string
mike@0 80 PCALL 2
mike@0 81 ! print_num(z); newline()
mike@0 82 LDGW _z
mike@0 83 CONST 0
mike@0 84 GLOBAL lib.print_num
mike@0 85 PCALL 1
mike@0 86 CONST 0
mike@0 87 GLOBAL lib.newline
mike@0 88 PCALL 0
mike@0 89 RETURN
mike@0 90 END
mike@0 91
mike@0 92 GLOVAR _z 4
mike@0 93 ! String "The final answer is calculated as "
mike@0 94 DEFINE g1
mike@0 95 STRING 5468652066696E616C20616E737765722069732063616C63756C617465642061
mike@0 96 STRING 732000
mike@0 97
mike@0 98 ! End
mike@0 99 ]]*)