Skip to content

Instantly share code, notes, and snippets.

@okayurisotto
Last active April 26, 2023 06:32
Show Gist options
  • Save okayurisotto/110e8fefca5a7fb03d958bea57399955 to your computer and use it in GitHub Desktop.
Save okayurisotto/110e8fefca5a7fb03d958bea57399955 to your computer and use it in GitHub Desktop.
(module
(func (export "fibo") (param $index i32) (result i32)
(local $a i32)
(local $b i32)
(local $c i32)
(local.set $a (i32.const 1))
(local.set $b (i32.const 0))
(loop $fibo-loop
(if
(i32.ge_s (local.get $index) (i32.const 0))
(then
(local.set $c (i32.add (local.get $a) (local.get $b)))
(local.set $a (local.get $b))
(local.set $b (local.get $c))
(local.set $index (i32.sub (local.get $index) (i32.const 1)))
(br $fibo-loop)
)
)
)
(local.get $b)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment