Exponentiation

We make use of exponentiation in our sin_taylor_series procedure, an algorithm which is not as trivial as it may seem when it comes to real numbers used as exponents; however, we are quite lucky because the Taylor series only uses natural numbers for that purpose, but, it is worth mentioning that, should we need larger exponents, the algorithm would have been too slow. Therefore, our implementation of an exponentiation algorithm is as basic as it gets--we simply multiply the parameter in XMM0 by itself ECX-1 times. ECX is decremented once because there is no need to calculate x1:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Trivial exponentiation function
; Parameters are:
; Values to exponentiate in XMM0
; Exponent is in ECX
; Return values are in XMM0
;-----------------------------------------------------
pow:
push ebp
mov ebp, esp
sub esp, 16

push ecx
dec ecx ; The inputs are already x1 so we decrement the exponent
movups [ebp - 16], xmm1

movaps xmm1, xmm0 ; We will be mutliplying XMM0 by XMM1
.l1:
mulps xmm0, xmm1
loop .l1

movups xmm1, [ebp - 16]
pop ecx
mov esp, ebp
pop ebp
ret
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset