Skip to content

Instantly share code, notes, and snippets.

@vbkmr
Created January 5, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbkmr/ac988b559ca22b2b322133978c65f040 to your computer and use it in GitHub Desktop.
Save vbkmr/ac988b559ca22b2b322133978c65f040 to your computer and use it in GitHub Desktop.
(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