Last active
December 22, 2018 20:38
-
-
Save eventhelix/6dc7f0dd849e875c5747e00056105654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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