# `retw`

[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/retw

**Return, 16-bit**

Category: Control flow

Requests the 16-bit near-return encoding, with an optional unsigned cleanup byte count.

8086 and later

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

## 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

- `retw`
- `retw imm16`

## Operands

- `imm16`: An unsigned 16-bit byte count, `0` to `65535`, added to the stack pointer after the return address is popped.

## Description

NASM also accepts it in 64-bit source, with an operand-size prefix, but there it removes only 2 bytes from the stack and jumps to that value zero-extended, an address below 64 KiB: it cannot return to a 64-bit caller, and ordinary 64-bit functions return with `ret`. The optional sole immediate operand is an unsigned 16-bit additional cleanup count, not a signed stack adjustment.

## Example

```x86
global _start

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

        retw 5

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