Download code

From LiteratePrograms

Jump to: navigation, search

Back to Fibonacci_numbers_(PIR)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

fib.pir

 1 
 2 .sub fib
 3 	.param int n
 4 	.local int f1
 5 	.local int f2
 6 
 7 	if n <= 1 goto END
 8 
 9 	n = n - 1
10 	f1 = fib(n)
11 	n = n - 1
12 	f2 = fib(n)
13 
14 	n = f1 + f2
15 
16 END:
17 	.return (n)
18 .end
19 
20 
21 .sub ffib
22 	.param int n
23 	.local int f1
24 	.local int f2
25 	.local int tmp
26 
27 	if n <= 1 goto END
28 
29 	f1 = 0
30 	f2 = 1
31 
32 	n = n - 1
33 LOOP:
34 	tmp = f2
35 	f2 = f1 + f2
36 	f1 = tmp
37 
38 	n = n - 1
39 	if n > 0 goto LOOP
40 
41 	n = f1
42 	if f1 > f2 goto END
43 	n = f2
44 
45 END:
46 	.return (n)
47 .end
48 
49 
50 .sub main :main
51 	.local int f
52 	.local int n
53 
54 	n = 0
55 
56 FIBLOOP:
57 	f = fib(n)
58 
59 	print n
60 	print ": "
61 	print f
62 	print "\n"
63 
64 	n = n + 1
65 
66 	if n > 30 goto FIBEND
67 
68 	goto FIBLOOP
69 
70 FIBEND:
71 	n = 0
72 
73 FFIBLOOP:
74 	f = ffib(n)
75 
76 	print n
77 	print ": "
78 	print f
79 	print "\n"
80 
81 	n = n + 1
82 
83 	if n > 30 goto END
84 
85 	goto FFIBLOOP
86 
87 END:
88 .end
89 
90 
91 
92 


Views
Personal tools