movsx
Move with sign extension
Copies a source into a register, sign-extending when the destination is wider.
386 and later
Intel's reference: MOVSX/MOVSXD
Used in
- Bytes, words, dwords and qwordsx86-64 assembly
CFPFAFZFSFDFOF –––––––
- Leaves every flag unchanged
Forms
Operands
reg- The destination register, usually wider than the source, as in
movsx eax, bl. r/m- The source register or memory location, usually narrower than the destination. The high-byte registers
ah,bh,chanddhcannot be used when the destination is a 64-bit register or one ofr8tor15at any size. acc- The accumulator:
al,ax,eaxorrax, whichever matches the operation’s size. The form accepts no other register in this position.
For example, movsx rax, byte [rdi] turns a stored 0xff into rax = -1, and movsx rax, ecx extends a signed 32-bit value to 64 bits.
For widening moves, the source width is independent of the destination width: byte, word and dword memory sources read 8, 16 and 32 bits. NASM also accepts equal-width and narrowing spellings. movsx ax, bx copies 16 bits; movsx ax, ebx retains the low 16 bits. These do not create a wider signed value. A 32-bit destination still 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
movsx rax, bl
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall