Slide 6.2: A sample program: finding Fibonacci numbers
Slide 6.4: MOVZX instruction
Home

Zero/Sign Extension of Integers


Zero/Sign extension of integers mainly deals with the problems caused by the restriction of MOV instruction: Both operands must be the same size.

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

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


Copying Smaller Values to Larger Ones
The following three examples show the problems of copying smaller values to larger ones.
 EAX = WORD  AX = WORD  AX = SWORD
 .data
 var   WORD  100h
 .code
 mov   eax, var
 call  WriteHex
 .data
 var   WORD  100h
 .code
 mov   eax, 0
 mov   ax, var
 call  WriteHex
 .data
 var   SWORD  0F1F0h
 ;   F1F0h = -3600
 .code
 mov   eax, 0
 mov   ax, var
 call  WriteHex
 Output  Output  Output