mirror of
https://github.com/eth-act/ere.git
synced 2026-04-03 03:00:17 -04:00
30 lines
516 B
Plaintext
30 lines
516 B
Plaintext
# Fibonacci
|
|
# Reads three u64 values from advice stack: fib_a, fib_b, n
|
|
# Returns nth fibonacci number
|
|
use miden::core::sys
|
|
|
|
begin
|
|
# Read inputs from advice stack
|
|
adv_push.1 # fib_a
|
|
adv_push.1 # fib_b
|
|
adv_push.1 # n
|
|
|
|
# Compute fibonacci
|
|
dup neq.0
|
|
while.true
|
|
movdn.2
|
|
dup.1
|
|
add
|
|
swap
|
|
movup.2
|
|
sub.1
|
|
dup neq.0
|
|
end
|
|
|
|
# Drop counter and one of the fibonacci values
|
|
drop
|
|
drop
|
|
|
|
exec.sys::truncate_stack
|
|
end
|