### comparison lab4/test/fib.p @ 0:bfdcc3820b32

Basis
author Mike Spivey Thu, 05 Oct 2017 08:04:15 +0100
comparison
equal inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* Fibonacci numbers by the usual recursion *)
2
3 (* fib -- fibonacci numbers *)
4 proc fib(n: integer): integer;
5 begin
6 if n <= 1 then
7 return 1
8 else
9 return fib(n-1) + fib(n-2)
10 end
11 end;
12
13 begin
14 print_num(fib(6)); newline()
15 end.
16
17 (*<<
18 13
19 >>*)
20
21 (*[[
22 @ picoPascal compiler output
23 .include "fixup.s"
24 .global pmain
25
26 @ proc fib(n: integer): integer;
27 .text
28 _fib:
29 mov ip, sp
30 stmfd sp!, {r0-r1}
31 stmfd sp!, {r4-r10, fp, ip, lr}
32 mov fp, sp
33 @ if n <= 1 then
34 ldr r0, [fp, #40]
35 cmp r0, #1
36 bgt .L3
37 @ return 1
38 mov r0, #1
39 b .L1
40 .L3:
41 @ return fib(n-1) + fib(n-2)
42 ldr r0, [fp, #40]
43 sub r0, r0, #1
44 bl _fib
45 mov r4, r0
46 ldr r0, [fp, #40]
47 sub r0, r0, #2
48 bl _fib
50 .L1:
51 ldmfd fp, {r4-r10, fp, sp, pc}
52 .ltorg
53
54 pmain:
55 mov ip, sp
56 stmfd sp!, {r4-r10, fp, ip, lr}
57 mov fp, sp
58 @ print_num(fib(6)); newline()
59 mov r0, #6
60 bl _fib
61 bl print_num
62 bl newline
63 ldmfd fp, {r4-r10, fp, sp, pc}
64 .ltorg
65
66 @ End
67 ]]*)