movsxw

Move word with sign extension

Copies a word source into a register, sign-extending when the destination is wider.

386 and later

Intel's reference: MOVSX/MOVSXD

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • movsxw eax, ax

Operands

reg
The destination register. Its width is selected independently of the source width; widening uses a larger destination.
r/m16
A 16-bit general-purpose register or word in memory, for example ax or word [rsi].

It reads 16 bits and sign-extends them into a 32- or 64-bit destination. For example, movsxw rax, [rdi] reads two bytes. NASM also accepts a 16-bit destination; that copies the word without widening it. A 32-bit destination clears the upper half of its 64-bit register.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        movsxw rax, bx

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall