-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfib_store.bb
45 lines (30 loc) · 845 Bytes
/
fib_store.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
; https://www.geeksforgeeks.org/print-fibonacci-sequence-using-2-variables/
(include "cornerstone/lib/core.bb")
(def @fib_ (params (%a u64*) (%b u64*) (%i u64) (%top u64)) void (do
(if (== %i %top) (do (return-void)))
(store (+ (load %a) (load %b)) %b)
(call @u64.println (args (load %b)))
(store (- (load %b) (load %a)) %a)
(call-tail @fib_ (args %a %b (+ %i 1) %top))
(return-void)
))
; b = a + old_b
; a = a + old_b - a
(def @fib (params (%n u64)) void (do
(if (>= %n 0) (do
(call @u64.println (args 0))
))
(if (>= %n 1) (do
(call @u64.println (args 1))
))
(auto %a u64)
(store 0 %a)
(auto %b u64)
(store 1 %b)
(call @fib_ (args %a %b 2 (+ %n 1)))
(return-void)
))
(def @main params i32 (do
(call @fib (args 10000))
(return 0)
))