Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "factorial" (func $factorial))
(func $factorial (; 0 ;) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(set_local $2
(i32.const 1)
)
(block $label$0
(br_if $label$0
(i32.lt_s
(get_local $0)
(i32.const 2)
)
)
(set_local $2
(i32.const 1)
)
(loop $label$1
(set_local $2
(i32.mul
(get_local $0)
(get_local $2)
)
)
(set_local $1
(i32.gt_s
(get_local $0)
(i32.const 2)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const -1)
)
)
(br_if $label$1
(get_local $1)
)
)
)
(get_local $2)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.