We also make use of factorials as we divide exponentiated values by a factorial of exponents thereof. The factorial of a given number n is the product of all positive integers less than or equal to the given number n:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Simple calculation of factorial
; Parameter is in ECX (number to calculate the factorial of)
; Return value is in XMM0 register
;-----------------------------------------------------
fact:
push ebp
mov ebp, esp
sub esp, 16 * 3
push ecx
movups [ebp - 16], xmm1
movups [ebp - 16 * 2], xmm2
mov dword[ebp - 16 * 3], 1.0
movd xmm2, [ebp - 16 * 3]
movlhps xmm2, xmm2
movsldup xmm2, xmm2
movaps xmm0, xmm2
movaps xmm1, xmm2
.l1:
mulps xmm0, xmm1
addps xmm1, xmm2
loop .l1
movups xmm2, [ebp - 16 * 2]
movups xmm1, [ebp - 16]
pop ecx
mov esp, ebp
pop ebp
ret