diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ppc/test/fib.p	Thu Oct 05 08:04:15 2017 +0100
@@ -0,0 +1,68 @@
+(* fib.p *)
+
+(* fib -- fibonacci numbers *)
+proc fib(n: integer): integer;
+begin
+  if n <= 1 then 
+    return 1 
+  else 
+    return fib(n-1) + fib(n-2)
+  end
+end;
+
+begin
+  print_num(fib(6)); newline()
+end.
+
+(*<<
+13
+>>*)
+
+(*[[
+MODULE Main 0 0
+IMPORT Lib 0
+ENDHDR
+
+PROC _fib 0 0 0
+!   if n <= 1 then 
+LDLW 16
+CONST 1
+JGT L2
+!     return 1 
+CONST 1
+RETURNW
+LABEL L2
+!     return fib(n-1) + fib(n-2)
+LDLW 16
+CONST 1
+MINUS
+CONST 0
+GLOBAL _fib
+PCALLW 1
+LDLW 16
+CONST 2
+MINUS
+CONST 0
+GLOBAL _fib
+PCALLW 1
+PLUS
+RETURNW
+END
+
+PROC MAIN 0 0 0
+!   print_num(fib(6)); newline()
+CONST 6
+CONST 0
+GLOBAL _fib
+PCALLW 1
+CONST 0
+GLOBAL lib.print_num
+PCALL 1
+CONST 0
+GLOBAL lib.newline
+PCALL 0
+RETURN
+END
+
+! End
+]]*)