x86 help value being store passes data type range


 
Thread Tools Search this Thread
Top Forums Programming x86 help value being store passes data type range
# 1  
Old 05-07-2011
x86 help value being store passes data type range

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


Code:
;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

# 2  
Old 05-07-2011
You might have better luck looking for floor than round. floor just converts 3.xxxx into 3.000, etc -- but you can make floor into a proper rounding function by just adding 0.5 before you floor.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Incompatible data type fpos_t in C

This is from a program I wrote over in 1998 that I am trying to compile on a linux machine: void write_line (FILE *fp, int rec_no, line_rec *arec) { fpos_t woffset; woffset = (rec_no - 1) * sizeof(line_rec); fsetpos(fp,&woffset); fwrite(arec,sizeof(line_rec),1,fp); }On the line... (2 Replies)
Discussion started by: wbport
2 Replies

2. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

3. Programming

help with data type sizes

i'm using a C program and running it on a linux server, i got 2 adressess of 2 variables, and 2 addresses of 2 chars, and compared it. and got the size of a int and the size of a char. why is a size of a int (4 bytes) bigger then the size of a char (1 byte)? also if i do &a-&b i get 1, but if i... (30 Replies)
Discussion started by: omega666
30 Replies

4. Web Development

Data type to use for prices with commas

Hi everybody, I`m very new with PHP and Databases and I having the follow issue with prices data.. The original information is in CSV files. The prices have formatted with commas and dots as follow: 12,300.99 -->(thousands separated by commas) 3,500.25 -->(thousands separated... (10 Replies)
Discussion started by: cgkmal
10 Replies

5. Solaris

Can not type in textbox ( Solaris 10 x86 )

My X86-Solaris 10- server after installed some softwares now has a bug. We can not type anything on the text box of Java applications or CDE such as Add printer or Raid Controller etc.. but i can type on the Command Line Terminal or Star Office applications :eek: I want to ask for a system... (4 Replies)
Discussion started by: tien86
4 Replies

6. Shell Programming and Scripting

Perl data type checking

I am using perl 5.8.0. I need to check some values to see it they are floats. Our system does not have Data::Types so I can't use is_float. Is there something else that I can use? The only thing in Data is Dump.pm. I am not allowed to download anything to our system so I have to use what I have.... (3 Replies)
Discussion started by: ajgwin
3 Replies

7. Shell Programming and Scripting

How to store Data in a File

I want to read a data from a read command and store it in a file...... Plz send me how I can do that Ex: read val and I want to store this val in a file called temp. (2 Replies)
Discussion started by: krishna_sicsr
2 Replies

8. Programming

data type limitation

I am writing some code to do analysis on the file system (HP-UX 11.11). I am using stat(..) to get file information. My problem is that the file-size may exceed the data types defined in 'sys/stat.h' & 'sys/types.h' respectively. Thus file-sizes in the Giga-byte range are not read correctly.... (2 Replies)
Discussion started by: ALTRUNVRSOFLN
2 Replies

9. Programming

FILE data type

Hi all, Can anyone tell me a little about the datatype FILE, which represents stream. What does its structure look like, and in which header file is it defined and so on... Ex : FILE *fp ; fp = fopen("filename", "w") ; (6 Replies)
Discussion started by: milhan
6 Replies
Login or Register to Ask a Question