Skip to content

Instantly share code, notes, and snippets.

@eventhelix
Last active December 22, 2018 20:38
Show Gist options
  • Save eventhelix/6dc7f0dd849e875c5747e00056105654 to your computer and use it in GitHub Desktop.
Save eventhelix/6dc7f0dd849e875c5747e00056105654 to your computer and use it in GitHub Desktop.
factorial(unsigned int):
mov eax, 1 ; The default return value eax=1
test edi, edi ; Check if the input parameter n is 0
je .L1 ; If n is 0, just return
.L2: ; Loop return variable
imul eax, edi ; eax = eax*n
sub edi, 1 ; n = n-1
jne .L2 ; Loop if n is non-zero
.L1: ; Jump label for n==0 case
ret ; Return result in eax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment