News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FPU status word

Started by SteveAsm, February 02, 2012, 01:18:30 AM

Previous topic - Next topic

SteveAsm

Hey guys,
I've been doing some experimenting, trying to determine what jump instructions work (sucessfully) based on storing the fpu status word in the AX register.
As in:

  FLD avalue
  FLD bvalue
  FCOM
  FSTSW AX
  FWAIT
  SAHF
;     <------- some jump instruction here  ----->  jne, jnl, jng, jnle, jz, je, jl, jg, jle, jge, jnz, ...etc.



Testing leads to a lot of hair pulling..., when some things appear to work, under some circumstances, but, then dont under others.
I've searched the forum archives and done some googling, but, I'm not finding too much information.
Any ideas or pointers would be appreciated.
Thanks,
steve

dedndave



qWord

you may better use fcomi[p], which directly set the flags -> JA/JB/...
FPU in a trice: SmplMath
It's that simple!

SteveAsm

Quote from: qWord on February 02, 2012, 08:23:12 AM
you may better use fcomi[p], which directly set the flags -> JA/JB/...

Hey qWord,
thanks for pointing that (FCOMI) out.
I didn't catch that in my searches the first time around and my reference book does not include it.

It looks like that could solve the problem, IF most processors in use include it.
I'm not so concerned with the newer ones.
It's the older desktops, laptops and notebooks I wonder about.

qWord

FCOMI was introduced with Intle's P6 (1995)  - don't worry about availability  :bg
FPU in a trice: SmplMath
It's that simple!

SteveAsm

Okay..., this is really odd.
I get these similar errors from JWasm and Masm:

JWasm  ::  Test2.asm(111) : Error A2049: Invalid instruction operands.

Masm :: Test2.asm(111) : error A2085: instruction or register not accepted in current CPU mode.

from this code segment:

  FILD aa
  FILD cc
  FCOMI
  jng  Label



Line #111 is the FCOMI instruction.
I have tried:
FCOMI ST(1)
FCOMI ST(0), ST(1)

Any ideas what this is all about ?

jj2007

Quote from: SteveAsm on February 02, 2012, 10:09:13 PM
Masm :: Test2.asm(111) : error A2085: instruction or register not accepted in current CPU mode.

include \masm32\include\masm32rt.inc
.686

dedndave

also, FILD will only work with words, dwords, or qwords
you may need to use a size override operator
SomeStuff db 0,0,0,0,0,0,0,80h
;
;
       FILD qword ptr SomeStuff

jj2007

Quote from: dedndave on February 02, 2012, 10:21:33 PM
also, FILD will only work with words, dwords, or qwords

FILD will should only work with words, dwords, or qwords

include \masm32\include\masm32rt.inc

.code
SomeStuff dq 1234567

start:
       FLD qword ptr SomeStuff  ; try FILD
       push eax
       fistp dword ptr [esp]
       pop eax
       print str$(eax)
       exit

end start


Of course, the result is gibberish :bg

SteveAsm

Quote from: jj2007 on February 02, 2012, 10:12:59 PM
include \masm32\include\masm32rt.inc
.686

Aha!
.686
this is the key.
Nowhere in my search results was that illustrated.

I had tried everything but .686 .

Thanks for that JJ,
Thanks once again guys.

raymond

Quote.686
this is the key.
Nowhere in my search results was that illustrated.

If you had looked at the first link given to you by dedndave, you would have found this:

QuoteNote: This instruction is valid only for the Pentium Pro and subsequent processors. It may not be supported by some assemblers (for MASM, the .686 directive must be used).
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

SteveAsm

Quote from: raymond on February 03, 2012, 01:35:18 AM
If you had looked at the first link given to you by dedndave, you would have found this:

QuoteNote: This instruction is valid only for the Pentium Pro and subsequent processors. It may not be supported by some assemblers (for MASM, the .686 directive must be used).

I don't want to appear antagonsitic, Ray, but I did look at Dave's first link.
There is a lot of information there, and I simply missed the Note.

SteveAsm

After spending the entire afternoon and evening playing with FCOMI, it doesn't appear that it solves any problems.
It eliminates a few steps, but, the result is still the same.
You are still limited to only a few branching options, as most of the x86 branch instruction are unusable.

qWord

Quote from: SteveAsm on February 03, 2012, 04:44:04 PMYou are still limited to only a few branching options, as most of the x86 branch instruction are unusable.

Which instructions are unusable?
FPU in a trice: SmplMath
It's that simple!