flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > FPU instruction problem?

Author
Thread Post new topic Reply to topic
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
fnstenv byte [ss:ESP - 0Ch]

Code:
fnstenv byte  [ss:ESP - 0Ch]
error: invalid size of operand.    
Post 18 May 2006, 23:13
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
AMD64 Architecture Programmer’s Manual Volume 5: "64-Bit Media and x87 Floating-Point Instructions wrote:
The FSTENV instruction takes a memory operand that specifies the start of either a
14-byte or 28-byte area in memory. The 14-byte operand is required for a 16-bit
operand-size; the 28-byte memory area is required for both 32-bit and 64-bit operand
sizes. The layout of the saved x87 environment within the specified memory area
depends on whether the processor is operating in protected or real mode. See “Media
and x87 Processor State” in volume 2 for details on how this instruction stores the x87
environment in memory. (Because FLDENV/FSTENV do not save the full 64-bit data
and instruction pointers, 64-bit applications should use FXSAVE/FXRSTOR, rather
than FLDENV/FSTENV.)


However "fnstenv dword [0]" nor "fnstenv word [0]" works

[edit]
Code:
format PE GUI 4.0

db $66
fnstenv [ss:ESP - 0Ch]
fnstenv [ss:ESP - 0Ch]    

Is disassembled by ollydbg as:
Code:
00401000 > $ 66:D97424 F4   FSTENV (14-BYTE) PTR SS:[ESP-C]
00401005   . D97424 F4      FSTENV (28-BYTE) PTR SS:[ESP-C]    


Note that I was wrong about word and dword because any address size is superfluous, I confused that with operand-size. How can be done the 14-byte version with FASM under 32/64 bits?
[/edit]
[edit2]
Well, it's me again... I was right, FASM needs "fnstenv word/dword [...]" to be supported. word and dword is not superfluous because that defines the operand-size. I must sleep something....[/edit2]


Last edited by LocoDelAssembly on 19 May 2006, 02:17; edited 2 times in total
Post 19 May 2006, 01:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
Don't specify the size.
Code:
fnstenv [esp-12]    
Post 19 May 2006, 01:56
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
The instructions from this family (like FXSAVE, etc.) all require memory blocks of various sizes that fasm doesn't have appropriate size specifiers for. Thus it requires them to be memory labels without size attributes at all.

To differ the FNSTENV forms we would need some size prefixes for 14 and 28 bytes, according to fasm's general rules. Or...

The only other considerable solution I came with so far is to allow NASM-like prefixes O16 and O32 (and perhaps O64, too), so that you would write "O16 FNSTENV [...]" etc.
Post 19 May 2006, 11:39
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
ok Smile
Post 20 May 2006, 03:33
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
But the O-notation is horrible and somewhat confusing - don't you think?
Post 29 May 2006, 09:17
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.