flat assembler
Message board for the users of flat assembler.

Index > Main > x86-64 MOVZX

Author
Thread Post new topic Reply to topic
msschlt



Joined: 13 Sep 2008
Posts: 6
msschlt
I have a question/problem:

movzx rax, byte [rsi] ;(work)
movzx rax, word [rsi] ;(works)
movzx rax, dword [rsi] ;(failed)

Failed with Error: invalid size of operand.
(FAsm 1.67.27 13 July 2008)

I don't understand.. IMHO this should work.
Post 13 Sep 2008, 22:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Code:
mov eax,dword[rsi]    
The zero extension is automatically applied to all 32bit destination register operands in 64bit mode.


Last edited by revolution on 13 Sep 2008, 23:54; edited 1 time in total
Post 13 Sep 2008, 23:39
View user's profile Send private message Visit poster's website Reply with quote
msschlt



Joined: 13 Sep 2008
Posts: 6
msschlt
Ah, ok.. thx Smile
Post 13 Sep 2008, 23:43
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
in case you missed it: "rax" is 64bits = qword, not dword.
Post 14 Sep 2008, 00:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Xorpd!



Joined: 21 Dec 2006
Posts: 161
Xorpd!
movzx rax, dword[rsi] is not encodable but there are a couple of variations:
Code:
C:\Asm\FASM\EXAMPLES\WIN64\my_example>link /dump /disasm movzx.obj
Microsoft (R) COFF/PE Dumper Version 8.00.50727.363
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file movzx.obj

File Type: COFF OBJECT

_main:
  0000000000000000: 63 06              movsxd      eax,dword ptr [rsi]
  0000000000000002: 8B 06              mov         eax,dword ptr [rsi]
  0000000000000004: C3                 ret

  Summary

           5 CODE
    

fasm doesn't permit the former encoding. It would be an interesting feature to permit all possible encodings, and in this case it can make a difference because the two operations do in fact use different pipelines on some processors, but it has been considered too much work for too little return to implement alternate encodings like this.
Post 14 Sep 2008, 06:14
View user's profile Send private message Visit poster's website Reply with quote
msschlt



Joined: 13 Sep 2008
Posts: 6
msschlt
vid wrote:
in case you missed it: "rax" is 64bits = qword, not dword.
I know "rax" is a 64bit. Wink

I want to mov with zero-ext. and zero the high 32bit.
Like e.g. movzx eax, word [esi] in 32bit.

But it's exactly like revolution says.

mov eax, [rsi]

..in 64bit mode, it kills the high 32bit autom.
I had thought the high 32bit remain unchanged.

Ok, stupid question..
Is there a way to mov without loosing the high 32bit in 64bit mode?
Post 14 Sep 2008, 07:47
View user's profile Send private message Reply with quote
Xorpd!



Joined: 21 Dec 2006
Posts: 161
Xorpd!
Quote:

Is there a way to mov without loosing the high 32bit in 64bit mode?

Assuming you want to copy ebx into eax and don't care if you destroy rcx, the sequence
Code:
mov  rcx, rax
xor  eax, ebx
xor  rax, rcx
    

should do the trick.
Alternative:
Code:
shrd rax, rbx, 32
ror  rax, 32
    
Post 14 Sep 2008, 08:05
View user's profile Send private message Visit poster's website Reply with quote
msschlt



Joined: 13 Sep 2008
Posts: 6
msschlt
Xorpd! wrote:

should do the trick.
Alternative:
Code:
shrd rax, rbx, 32
ror  rax, 32
    
Nice trick. Wink
Thank you Xorpd!
Post 14 Sep 2008, 08:09
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-2020, Tomasz Grysztar.

Powered by rwasa.