MOVSX Instruction


The MOVSX instruction (move with sign-extend) copies the contents of a source operand into a destination operand and sign-extends the value to either 16 or 32 bits.

Sign Extension of an Integer
Source (8 bits) Destination (16 bits)
0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0

MOVSX — Move with Sign-Extend (386+)
Usage: MOVSX dest, src

Flag O D I S Z A P C
Result                

Copies a byte or word from a source operand to a destination operand and sign-extends into the upper half of the destination.
Clocks
Operands 286 386 486 Size Bytes
reg, reg   3 3 3
reg, mem   6 3 3-7

 AX = BYTE   SDWORD = SWORD   SWORD = SDWORD 
 .data
 var    BYTE  0F0h
 .code
 mov    eax, 0
 movsx  ax, var
 call   WriteHex

 .data
 var1   SWORD   -3600
 var2   SDWORD  ?
 .code
 
 
 mov    eax, var2
 call   WriteInt
 


 .data
 var1   SWORD   ?
 var2   SDWORD  0FFFFF123h
 .code
 
 
 
 movsx  eax, var1
 call   WriteHex
 

 Output  Output  Output
   



  -3600     0FFFFF123h