retw

Return, 16-bit

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

8086 and later

Intel's reference: RET

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

Forms

  • retw
  • retw

Operands

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

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.

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