flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > 'mov eax, cs' (possibly bug)

Author
Thread Post new topic Reply to topic
TDCNL



Joined: 25 Jan 2006
Posts: 56
TDCNL 14 Aug 2006, 13:36
I am currently busy with OS-Dev and in pmode I use 'mov eax, cs' to put CS into EAX, (use32 directive is used before 'mov eax, cs') and FASM does not report any error.

While this should be 'movzx eax, cs', is this right?

I haven't looked at the generated code to see what is actually generated, but shouldn't FASM at least report a warning?

EDIT: Did some review on these instructions, it seems 'mov eax, cs' command isn't even valid and neither is 'movzx eax, cs'. Does FASM convert 'mov eax, cs' to 'mov ax, cs' ?

-- Greetz, TDCNL (aka new nick BugHunter)

_________________
:: The Dutch Cracker ::
Post 14 Aug 2006, 13:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 14 Aug 2006, 14:50
No, "MOV AX,CS" and "MOV EAX,CS" are two different instructions. It was never documented properly by Intel manuals, but the AMD ones do it well.
Post 14 Aug 2006, 14:50
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 14 Aug 2006, 17:00
Intel documents it very well:
Quote:

When operating in 32-bit mode and moving data between a segment register and a generalpurpose
register, the 32-bit IA-32 processors do not require the use of the 16-bit operand-size
prefix (a byte with the value 66H) with this instruction, but most assemblers will insert it if the
standard form of the instruction is used (for example, MOV DS, AX). The processor will
execute this instruction correctly, but it will usually require an extra clock. With most assemblers,
using the instruction form MOV DS, EAX will avoid this unneeded 66H prefix. When the
processor executes the instruction with a 32-bit general-purpose register, it assumes that the 16
least-significant bits of the general-purpose register are the destination or source operand. If the
register is a destination operand, the resulting value in the two high-order bytes of the register
is implementation dependent. For the Pentium 4, Intel Xeon, and P6 family processors, the two
high-order bytes are filled with zeros; for earlier 32-bit IA-32 processors, the two high order
bytes are undefined
.
Post 14 Aug 2006, 17:00
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8349
Location: Kraków, Poland
Tomasz Grysztar 14 Aug 2006, 17:52
But they don't define distinct operand forms for those instructions and thus this feature is not visible in general reference (see attached pic).
fasm uses the syntax as defined by AMD - so you've got "mov eax,ds" and "mov ax,ds", but only "mov ds,ax" in reverse direction (and so fasm doesn't fit into "the most assemblers" mentioned by Intel).

There is also a similar story with the LAR and LSL instructions.


Description: Intel manual vs. AMD one
Filesize: 20.15 KB
Viewed: 8787 Time(s)

movman.JPG


Post 14 Aug 2006, 17:52
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 14 Aug 2006, 18:06
You're right, Intel is too brief in this reference.

On the other side, AMD often doesn't mention some important features of an instruction. For instance, POP [ESP] first increments ESP, then stores. AMD doesn't say anything about it.
Post 14 Aug 2006, 18:06
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 15 Aug 2006, 07:38
Conclusion? You need both manuals and some common sence?
Post 15 Aug 2006, 07:38
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
TDCNL



Joined: 25 Jan 2006
Posts: 56
TDCNL 18 Aug 2006, 12:21
It's clear now Smile
Btw I didn't look deeply into FASM manual yet but is this behaviour documented?

_________________
:: The Dutch Cracker ::
Post 18 Aug 2006, 12:21
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.