Hi im very new to x86 programming and was wonder if there a function or ways to solve my problem. I believe the reason for my inaccurate result are from passing floating point number beyond what a SWORD could hold.
So far I been looking for a function that would allow me to round the floating point number but I cant seem to find any of that info on google. Any help would be appreciated. Thank you.
result from this...
sRoot(4/1) = 2/1
sRoot(9/1) = -13543/4096
sRoot(2/1) = 24023/-14336
;Find the square root and display the new frac. This uses the babylonian algorithm.
sRoot proc USES ebx, num:SWORD, den:SWORD, num2:SWORD, den2:SWORD
LOCAL dholder:SWORD ;store the past result
LOCAL nholder:SWORD ;store the past result
LOCAL counter:SDWORD
mov counter,0
invoke divFrac, num2,den2,10,1
mov num,cx
mov den,dx
invoke addFrac, 10,1,num,den
mov num,cx
mov den,dx
invoke mulFrac, 1,2,num,den
mov num,cx
mov den,dx
top:
invoke divFrac, num2,den2,num,den
mov nholder,cx
mov dholder,dx
invoke addFrac, num,den,nholder,dholder
mov nholder,cx
mov dholder,dx
invoke mulFrac, 1,2,nholder,dholder
mov num,cx
mov den,dx
inc counter
cmp counter,10
je done
jne top
done:
ret
sRoot endp
;addFrac and mulFrac accept similar value as divFrac
; divides two fractions puts numerator in ecx and denominator in edx
divFrac PROC USES eax ebx, num1:SWORD, den1:SWORD, num2:SWORD, den2:SWORD
LOCAL rNum:SDWORD ;store orignal value
LOCAL rDen:SDWORD
mov ax,0 ;set ax to 0
mov ax,num1 ;move num1 to ax register
imul ax,den2 ;sign multiply den2 to ax
movsx ecx,ax ;mov ax with sign ext (SWORD) to ecx register
mov ax,0
mov ax,num2
imul ax,den1
movsx edx,ax
mov rNum,ecx
mov rDen,edx
invoke gcd,rNum,rDen
ret ;return address
divFrac ENDP