MOVSX Instruction


The 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
 INCLUDE Irvine32.inc 
 .data
  var    BYTE  0F0h
 .code
 main PROC
  mov    eax, 0
  movsx  ax, var
  call   WriteHex
  exit
 main ENDP
 END main
 INCLUDE Irvine32.inc
 .data
  var1  SWORD   -3600
  var2  SDWORD  ?
 .code
 main PROC

 

 

  mov    eax, var2
  call   WriteInt
  exit
 main ENDP
 END main
 

 


 INCLUDE Irvine32.inc
 .data
  var1 SWORD  ?
  var2 SDWORD 0FFFFF123h
 .code
 main PROC
 
  

  

  

  movsx  eax, var1
  call   WriteHex
  exit
 main ENDP
 END main
 

 

Output Output Output

 

 
  -3600     0FFFFF123h  






      “A guy goes ice fishing for the very first time.    
      All of a sudden, he hears a voice. “There are no fish under the ice!”    
      He ignores it and moves to another area, cuts a hole and tosses his line in.    
      Again, he hears the booming voice: “There are no fish under the ice!”    
      He nervously looks up and asks, “Lord? Is that you?” “No, this is the rink manager!”    
      ― Emmy Award-winning actress Allison Janney