| <<< Sign Extending Unsigned Value | Index | The XLATB Instruction >>> |
The 80386/486/Pentium processors provide instructions that move and extend a value to a larger data size in a single step.
MOVSX moves a signed value into a register and sign-extends it with 1.
MOVZX moves an unsigned value into a register and zero-extends it with zero.
mov bx, 0C3EEh ; Sign bit of bl is now 1: BH == 1100 0011, BL == 1110 1110
movsx ebx, bx ; Load signed 16-bit value into 32-bit register and sign-extend
; EBX is now equal FFFFC3EEh
movzx dx, bl ; Load unsigned 8-bit value into 16-bit register and zero-extend
; DX is now equal 00EEh
MOVSX and MOVZX instructions usually execute much faster than the equivalent CBW, CWD, CWDE, and CDQ.
| <<< Sign Extending Unsigned Value | Index | The XLATB Instruction >>> |