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

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


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

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]

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

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)

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?


November 17th, 2000, 20:27
in that case yes, but in other cases:
movsx eax,ax where ax=0f123h gives eax=0fffff123h

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