flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > The XCHG instruction is not fully optimized

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 316
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
Code:
use64
xchg eax,eax ;-> assembled: 87h C0h, it could be like in 32-bit mode: 90h    

_________________
smaller is better
Post 31 Jul 2020, 19:28
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7781
Location: Kraków, Poland
Tomasz Grysztar
In long mode opcode 90h is treated specially in order to be a true NOP, therefore it does not clear the upper portion of the 64-bit register, while "xchg eax,eax" does.

On these forums you may even find my post from the time when I was adding 64-bit support to fasm and it was one of the issues that I needed to test on actual hardware to make sure that I interpreted the manuals correctly. And the tests confirmed that it was behaving this way.
Post 31 Jul 2020, 20:57
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 316
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
I forgot that in 64-bit mode the upper portion of general purpose registers is cleared when operations on 32-bit registers (surely except for the TEST instruction).

Thanks for the clarification.

_________________
smaller is better
Post 31 Jul 2020, 21:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17624
Location: In your JS exploiting you and your system
revolution
CandyMan wrote:
I forgot that in 64-bit mode the upper portion of general purpose registers is cleared when operations on 32-bit registers (surely except for the TEST instruction).
Zeroing of the upper bits is only on register write. TEST does not write to anything except flags, so no zeroing. Same with CMP.
Post 31 Jul 2020, 22:29
View user's profile Send private message Visit poster's website 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 GitHub, YouTube, Twitter.

Website powered by rwasa.