Re: whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- From: Terje Mathisen <"terje.mathisen at tmsw.no">
- Date: Wed, 27 May 2009 21:39:07 +0200
Stephen Sprunk wrote:
The 66h prefix normally does exactly what the manual says, but that isn't so helpful in this case...
The basic problem is that there aren't different instruction encodings for 16-bit and 32-bit operations; a code segment (or is that a page?) has a "default" operand size, and if you want the "other" size, you need the 66h prefix. For instance, in 16-bit mode a "MOV AX, BX" can be turned into "MOV EAX, EBX" by adding a 66h prefix. Conversely, in 32-bit mode a "MOV EAX, EBX" can be turned into "MOV AX, BX" by adding the same 66h prefix.
However, NOP doesn't take any operands, so the 66h prefix has absolutely no effect. Why use it? Because this sequence:
NOP does in fact take a register operand: (E)AX!
90h is the opcode for XCHG AX,AX (or XCHG EAX,EAX in 32-bit mode), so adding one or more 66h prefix bytes change the code from 16 to 32 bit or vice versa. :-)
OTOH, this isn't really true any longer: Even though the asm code for XCHG EAX,EAX is indeed 90h, by the time a modern x86 cpu sees the code, it knows that this doesn't modify anything, and therefore it can disregard the current status of the EAX register.
I.e. NOP today is a "true No-operation", not just a regular one-byte opcode that happens to not modify anything.
BTW, MOVing any register to itself (MOV EAX,EAX) is a two-byte NO-OP, but unlike the 66h/90h combination it isn't specialcased by the decoder, so it does affect the reorder buffer register pressure.
Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
.
- References:
- whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- From: omkarenator
- Re: whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- From: Stephen Sprunk
- whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- Prev by Date: Re: whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- Next by Date: Special Tips 4 u
- Previous by thread: Re: whats the use of "data16 nop" instruction generated by gas on x86 and x86_64
- Next by thread: (paypal accpet)(www.salewto.com)we wholesale nike shoes, jordan shoes, louis vuitton shoes, lacoste shoes, evisu shoes, (paypal accpet)(www.salewto.com)puma shoes, prada shoes, gucci shoes, max shoes, af1 shoes, running shoes, adidas shoes
- Index(es):
Relevant Pages
|