Files
ere/tests/miden/fib/fib.masm
2025-12-15 12:13:49 +08:00

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