The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 07:10:11 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  fcomip or converter problem
« previous next »
Pages: [1] Print
Author Topic: fcomip or converter problem  (Read 4199 times)
RuiLoureiro
Member
*****
Gender: Male
Posts: 590


fcomip or converter problem
« on: April 21, 2012, 07:43:17 PM »

                I type the string '0.1'
                and i convert it to _Delta
                I show both _Delta0 and _Delta and they are 0.10000000

                When i Test, it jumps to label _erro, so
                _Delta > _Delta0 !

                If _Delta <= _Delta0 it should exit with CLC
                is what i want.
               
                What is the problem ? What's the solution ?

Code:
.DATA
_Delta      dt 0
_Delta0     dt 1.0e-1   
;.............................

                ; -----------
                ; Test _Delta
                ; -----------
                fld     tbyte ptr _Delta0       ;st(1)
                fld     tbyte ptr _Delta        ;st(0)
                ;
                fcomip  st(0), st(1)
                fwait
                jpe     short _erro1
                ja      short _erro

                fstp    st                      ;remove source
                clc
                ret

    _erro1:     fstp    st                      ;remove source
                mov     eax, 1
                stc
                ret     
                ;
                ; EXIT  «««HERE !!!
                ;
    _erro:      fstp    st                      ;remove source
                mov     eax, 0
                stc
                ret

    I decided to use my converter and do this
    and now _Delta = _Delta0
   
Code:
.DATA
_sDelta0    db '0.1', 0   

_Delta      dt 0
_Delta0     dt ?   
;.............................
                ;
                ; convert _sDelta0 to _Delta0
                ; »»»»»»»»»»»»»»»»»»»»»»»»»»»
                invoke  CvRclToRel, addr _sDelta0, addr _Delta0
                jc      _erro1
               
                ; -----------
                ; Test _Delta
                ; -----------
                fld     tbyte ptr _Delta0       ;st(1)
                fld     tbyte ptr _Delta        ;st(0)
                ;
                fcomip  st(0), st(1)
                fwait
                jpe     short _erro1
                ja      short _erro

                fstp    st                      ;remove source

                ; »»»»»»»»»»»»»»»»»
                ; EXIT  «««HERE !!!             ««««««««««««««««««««««
                ; »»»»»»»»»»»»»»»»»
                clc
                ret

    _erro1:     fstp    st                      ;remove source
                mov     eax, 1
                stc
                ret     

    _erro:      fstp    st                      ;remove source
                mov     eax, 0
                stc
                ret
Logged
qWord
Member
*****
Posts: 1425



Re: fcomip or converter problem
« Reply #1 on: April 21, 2012, 08:26:31 PM »

have you tried to analyse it with OllyDbg? Also, testing for equality is not trivial.

BTW: fwait is not needed.
Logged

FPU in a trice: SmplMath
It's that simple!
raymond
Member
*****
Gender: Male
Posts: 941


Aging newbie


Re: fcomip or converter problem
« Reply #2 on: April 22, 2012, 03:46:12 AM »

It is obvious that if you convert two identical strings with the same procedure, you will get identical results.

The procedure used by the assembler to convert your 0.1 string in the .data section is not necessarily identical to your own conversion procedure and could result in a small difference which could be picked up by the fcomip instruction. Using a debugger, look at the memory locations where the values are stored and compare their least significant bytes. Even if the difference is only 1, one would be considered larger than the other.
Logged

When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com
RuiLoureiro
Member
*****
Gender: Male
Posts: 590


Re: fcomip or converter problem
« Reply #3 on: April 22, 2012, 02:05:39 PM »

qWord,

have you tried to analyse it with OllyDbg? Also, testing for equality is not trivial.
               Thanks for reply
                I dont like to use it !
                I will go to use my converter to get _Delta0 before testing wink
               
Quote
BTW: fwait is not needed.
               Ok thanks  ThumbsUp
Logged
RuiLoureiro
Member
*****
Gender: Male
Posts: 590


Re: fcomip or converter problem
« Reply #4 on: April 22, 2012, 02:13:14 PM »

raymond,
          Thanks for reply
Quote
The procedure used by the assembler to convert your 0.1 string in the .data section
is not necessarily identical to your own conversion procedure and
could result in a small difference which could be picked up by the
fcomip instruction.
              The problem is the assembler converter, i think

              I also used your converter to convert the 0.1 string
              and it is not equal to that of .data section.
              In any case i solved the problem.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!