flat assembler
Message board for the users of flat assembler.

flat assembler > Main > X86-64 sahf illegal instruction

Author
Thread Post new topic Reply to topic
mehble



Joined: 23 Nov 2008
Posts: 2
Hey guys... im doing some floating point stuff in my 64 bit program and i need to compare two flloating point numbers and jump for a condition. What i tried but didnt work was the following:

faddp st1,st0
fcomp [ex2] ; ex2 is the value 4.0
fstsw ax
sahf ;ILLEGAL instruction
ja finished

i would really appreciate it if anyone has an alternative to this or a way around the problems.

Thanks, Mark
Post 23 Nov 2008, 11:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16778
Location: In your JS exploiting you and your system
Use fcomi.
Post 23 Nov 2008, 12:29
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 953
Location: Czechoslovakia
I wonder what version of FASM are you using? Both 1.67.21 and 1.67.29 (newest) accepts SAHF and LAHF.
Post 24 Nov 2008, 09:12
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
BTW, don't forget that when comparing two FP numbers which are product of some computation, you should compare with some margin, eg:
if num1-margin < num2 < num1+margin then numbers are equal.

Of course this may not always apply, but mostly it does
Post 24 Nov 2008, 10:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
MazeGen,

They do accept, but…
Intel SDM wrote:
This instruction executes as described above in compatibility mode and legacy mode. It is valid in 64-bit mode only if CPUID.80000001H:ECX.LAHF-SAHF[bit 0] = 1.
Post 24 Nov 2008, 11:58
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 953
Location: Czechoslovakia
barld: yes (and ref.x86asm.net/coder64.html says the same) but only early steppings of EM64T architecture don't support LAHF and SAHF and as long as we can't set some "100%-64-bit-compatibility" option in FASM, LAHF and SAHF should be enabled.
Post 24 Nov 2008, 12:22
View user's profile Send private message Visit poster's website Reply with quote
mehble



Joined: 23 Nov 2008
Posts: 2
i used fcomi instead... thanks revolution.

Code:
I wonder what version of FASM are you using? Both 1.67.21 and 1.67.29 (newest) accepts SAHF and LAHF. 
    


Fasm does allow it to assembler (SAHF and LAHF)... no problems. But if you run it through a debugger for example fdbg001B it will still come up as an illegal instruction and hence the program will just skip over it.
Post 24 Nov 2008, 12:23
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
mehble,

FDBG decode 0x9E as "illegal sahf" but F7/F8 doesn't generate #UD fault and sahf works as specified? Probably FDBG's authors should check aforementioned CPUID flag…

MazeGen wrote:
…barld…
Yay, another spelling of my nick! Only 117 left… Wink
Post 24 Nov 2008, 12:42
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 447
Location: Czech republic, Slovak republic
thanks guys, I'll update that in fdbg
Post 24 Nov 2008, 14:23
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Use TEST ah,condition_bitmask.
Post 24 Nov 2008, 14:45
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 447
Location: Czech republic, Slovak republic
Hi, I implemented the checking of LAHF / SAHF instructions support into fdbg so now it doesn't output such confusing informations.
http://board.flatassembler.net/topic.php?p=85361#85361
Post 25 Nov 2008, 14:25
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.