annotate ppc/test/fib.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 (* fib.p *)
mike@0 2
mike@0 3 (* fib -- fibonacci numbers *)
mike@0 4 proc fib(n: integer): integer;
mike@0 5 begin
mike@0 6 if n <= 1 then
mike@0 7 return 1
mike@0 8 else
mike@0 9 return fib(n-1) + fib(n-2)
mike@0 10 end
mike@0 11 end;
mike@0 12
mike@0 13 begin
mike@0 14 print_num(fib(6)); newline()
mike@0 15 end.
mike@0 16
mike@0 17 (*<<
mike@0 18 13
mike@0 19 >>*)
mike@0 20
mike@0 21 (*[[
mike@0 22 MODULE Main 0 0
mike@0 23 IMPORT Lib 0
mike@0 24 ENDHDR
mike@0 25
mike@0 26 PROC _fib 0 0 0
mike@0 27 ! if n <= 1 then
mike@0 28 LDLW 16
mike@0 29 CONST 1
mike@0 30 JGT L2
mike@0 31 ! return 1
mike@0 32 CONST 1
mike@0 33 RETURNW
mike@0 34 LABEL L2
mike@0 35 ! return fib(n-1) + fib(n-2)
mike@0 36 LDLW 16
mike@0 37 CONST 1
mike@0 38 MINUS
mike@0 39 CONST 0
mike@0 40 GLOBAL _fib
mike@0 41 PCALLW 1
mike@0 42 LDLW 16
mike@0 43 CONST 2
mike@0 44 MINUS
mike@0 45 CONST 0
mike@0 46 GLOBAL _fib
mike@0 47 PCALLW 1
mike@0 48 PLUS
mike@0 49 RETURNW
mike@0 50 END
mike@0 51
mike@0 52 PROC MAIN 0 0 0
mike@0 53 ! print_num(fib(6)); newline()
mike@0 54 CONST 6
mike@0 55 CONST 0
mike@0 56 GLOBAL _fib
mike@0 57 PCALLW 1
mike@0 58 CONST 0
mike@0 59 GLOBAL lib.print_num
mike@0 60 PCALL 1
mike@0 61 CONST 0
mike@0 62 GLOBAL lib.newline
mike@0 63 PCALL 0
mike@0 64 RETURN
mike@0 65 END
mike@0 66
mike@0 67 ! End
mike@0 68 ]]*)