Skip to content

Instantly share code, notes, and snippets.

@ndemonner
Created March 1, 2015 19:23
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 ndemonner/25a76ae27fdda1725235 to your computer and use it in GitHub Desktop.
Save ndemonner/25a76ae27fdda1725235 to your computer and use it in GitHub Desktop.
# Factorial!
push 10
store 0
push 1
store 1
#
# Put the counter value on the stack. If it's 0, we're done
# and register 1 contains the final result.
#
recurse:
load 0
jz :finish
load 1 # result
load 0 # count
mul
store 1 # new result
load 0
push 1
sub
store 0
jmp :recurse
finish:
load 1
stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment