# `movsx`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/movsx

**Move with sign extension**

Category: Arithmetic

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

386 and later

[Intel's reference: MOVSX/MOVSXD](https://intel.github.io/SDM/instruction/MOVSX-MOVSXD.html)

Used in: [Bytes, words, dwords and qwords](https://asm-editor.specy.app/learn/courses/x86/introduction/bytes-words-dwords-and-qwords.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

## Forms

- `movsx reg, r/m` (16, 32, 64)
  - `movsx reg16, r/m8`
  - `movsx reg32, r/m8`
  - `movsx reg64, r/m8`
  - `movsx reg16, r/m16`
  - `movsx reg32, r/m16`
  - `movsx reg64, r/m16`
  - `movsx reg16, r/m32`
  - `movsx reg32, r/m32`
  - `movsx reg64, r/m32`
- `movsx acc, acc` (16, 32, 64)
  - `movsx ax, al`: 8086 and later
  - `movsx eax, ax`
  - `movsx rax, eax`

## 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`, `ch` and `dh` cannot be used when the destination is a 64-bit register or one of `r8` to `r15` at any size.
- `acc`: The accumulator: `al`, `ax`, `eax` or `rax`, whichever matches the operation’s size. The form accepts no other register in this position.

## Description

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.

## Example

```x86
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
```
