Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: mov seg, re...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 10 Topic 4579 of 4728
Post > Topic >>

Re: mov seg, reg/mov reg, seg and size prefix

by "Rod Pemberton" <spamtrap@[EMAIL PROTECTED] > Mar 19, 2008 at 09:05 AM

"Frank Kotler" <spamtrap@[EMAIL PROTECTED]
> wrote in message
news:JN2Ej.7276$rR1.5825@[EMAIL PROTECTED]
> rhyde@[EMAIL PROTECTED]
 wrote:
> > One curious thing I've noticed is that the presence/absence of a 0x66
> > size prefix byte, for 16-bit only instructions, is all over the map.
> > For example, consider the following two instructions:
> >
> > mov ds, ax
> > mov ax, ds
> >
> > Clearly, there are only 16-bit versions of these two instructions.
>
> True, "mov ds, ax" and "mov ds, eax" - with and without the prefix, IOW
> - do exactly the same thing. "mov ax, ds" and "mov eax, ds" are *not*
> the same, and the prefix is relevant.
>
> > Some assemblers *always* put a 0x66 size prefix byte in front of the
> > encodings, some never do, and at least one (MASM) puts size prefix
> > bytes before one but not the other.
>
> That's interesting... Nasm went round-and-round on the issue a while
> back. Referring to segreg as a *destination*, Intel said "most
> assemblers" emit the size prefix, and you could use "mov ds, eax"
> (absurd, on the face of it) to avoid it. It sounded like they were
> saying you should do it, but if you read closer, they almost said that
> those "most assemblers" were "doing it wrong" to emit the useless prefix
> - or making us write something that *looks* like a size-mismatch to
> avoid it. We took an informal survey, and Masm was about the only
> assembler that *was* doing it, at that time (Nasm used to, but stopped).
> Sounds like Masm has stopped, too. Who's doing "both"?
>

Wow...  That's not what I got from their doc's.  What I got was, "If you
use
the 16-bit form of mov to a segment register in 32-bit mode, instead of
using the 32-bit form of mov to a segment register in 32-bit mode, some
assemblers will generate an unecessary 0x66 operand size override prefix
due
to the 16-bit segment register in the instruction."  Since Randall was
referring to 16-bit instructions, I thought he was referring to 16-bit
mode
too...

This is what I would expect an assembler to do:

BITS 16
mov ds, ax  ; no 0x66
mov ds, eax  ; yes 0x66, but unneeded
mov ax, ds ; no 0x66
mov eax, ds ; yes 0x66 - required because of cpu dependent 32-bit
operation

BITS 32
mov ds, ax  ; yes 0x66, but unneeded
mov ds, eax  ; no 0x66
mov ax, ds ; yes 0x66 - required to ensure 16-bit only operation
mov eax, ds ; no 0x66

The reason I expect that is because the address and operand size prefixes
can be used to execute 16-bit code in a 32-bit segment and vice-versa. 
So,
I expect the assembler to place the overrides properly, even if
unecessary.
But, the override prefixes are required to ensure the proper operation for
ax/eax.


Rod Pemberton
 




 10 Posts in Topic:
mov seg, reg/mov reg, seg and size prefix
"rhyde@[EMAIL PROTEC  2008-03-18 14:24:20 
Re: mov seg, reg/mov reg, seg and size prefix
"Wolfgang Kern"  2008-03-19 00:54:57 
Re: mov seg, reg/mov reg, seg and size prefix
s_dubrovich <spamtrap@  2008-03-18 16:23:32 
Re: mov seg, reg/mov reg, seg and size prefix
Frank Kotler <spamtra  2008-03-19 06:55:37 
Re: mov seg, reg/mov reg, seg and size prefix
"Rod Pemberton"  2008-03-19 09:05:52 
Re: mov seg, reg/mov reg, seg and size prefix
Frank Kotler <spamtra  2008-03-19 20:17:25 
Re: mov seg, reg/mov reg, seg and size prefix
"Rod Pemberton"  2008-03-20 05:39:58 
Re: mov seg, reg/mov reg, seg and size prefix
Frank Kotler <spamtra  2008-03-21 09:38:20 
Re: mov seg, reg/mov reg, seg and size prefix
"rhyde@[EMAIL PROTEC  2008-03-27 09:29:22 
Re: mov seg, reg/mov reg, seg and size prefix
"Rod Pemberton"  2008-03-27 15:51:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 0:42:06 CDT 2008.