# `retnq`

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

**Near return, 64-bit**

Category: Control flow

Pops a 64-bit near return address into rip and jumps there, then adds the optional imm16 to rsp.

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

- `retnq`
- `retnq imm16`

## Operands

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

## Description

In 64-bit mode it pops an 8-byte return address from `[rsp]` into `rip` and advances `rsp` by 8. `ret` and `retn` are synonyms; the `q` suffix explicitly requests the 64-bit form.

The optional sole operand is an unsigned 16-bit count of additional bytes to remove from the stack after popping the return address. For example, `ret 16` advances `rsp` by 24 in total. A negative spelling does not subtract stack space: encoded `0xffff` means cleanup of 65535 bytes.

## Example

```x86
global _start

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

        retnq 5

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