Download code

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


hijacker
hijacker
hijacker
hijacker