View Full Version : [b]Help with ASM Instruction Please![/b]

xOptiMus

November 17th, 2000, 12:33

Hi there,

Can anyone explain what "MOVZX" actually does?

I know what MOV does. So what is the difference between MOV and MOVZX?

Hope someone can help

TIA

xOptiMus

PS Can't get the hang of them Code tags for bold, underline etc!

cronos

November 17th, 2000, 13:05

movzx is move with zero extend. it moves a reg or memory operand into another reg with more bits, extending the result with zero bits. So:

movzx eax,ax

where ax=0ffh means eax=0ffh after the instruction, or to make this a bit clearer, if eax=12345678h before the instruction then eax=5678h afterwards.

movzx eax,[400000]

means eax= the byte from [400000] but eax is 32bits, so the other bits become zero

You also have

movzx ax,al

movzx eax,al

etc, where 8 bits are moved into 16/32 and the rest become zero.

or in a 16-bit segment

movzx ax,ds:[0100]

etc

finally, contrast this with movsx which sign extends the item rather than zero extending it.

So

movsx eax,ax where ax=1 gives eax=1

movsx eax,ax where ax=0ffh gives eax=0ffffffffh (ie where ax=-1 gives eax=-1)

xOptiMus

November 17th, 2000, 14:43

Hi Cronos

Thanks for explaining the MOVZX instruction, I understand now.

However, I don't see the difference between MOVSX and MOV: surely

movsx eax,ax where ax=1 gives eax=1

is the same as

mov eax, ax isn't it? or am I wrong?

xOptiMus

cronos

November 17th, 2000, 20:27

in that case yes, but in other cases:

movsx eax,ax where ax=0f123h gives eax=0fffff123h

and

movzx eax,ax where ax=0f123h gives eax=0f123h

Powered by vBulletin® Version 4.2.2 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.