# `ret`

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

**Near return, default size**

Category: Control flow

Pops the 8-byte return address from the stack into rip and transfers control to it.

8086 and later

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

Used in: [The x86-64 instruction set](https://asm-editor.specy.app/learn/courses/x86/introduction/the-x86-instruction-set.md) (x86-64 assembly), [call, ret and the System V convention](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/call-ret-and-the-system-v-convention.md) (x86-64 assembly), [SSE2 scalar and packed arithmetic](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/sse-and-packed-arithmetic.md) (x86-64 assembly), [Interrupts, exceptions and signals](https://asm-editor.specy.app/learn/courses/x86/talking-to-the-outside-world/interrupts-exceptions-and-signals.md) (x86-64 assembly), [A subroutine with its arguments in registers](https://asm-editor.specy.app/learn/courses/x86/examples/subroutine-with-register-arguments.md) (x86-64 assembly), [Stack arguments and a stack frame](https://asm-editor.specy.app/learn/courses/x86/examples/subroutine-with-stack-arguments.md) (x86-64 assembly), [Recursion: factorial and Fibonacci](https://asm-editor.specy.app/learn/courses/x86/examples/factorial-and-fibonacci.md) (x86-64 assembly), [A jump table](https://asm-editor.specy.app/learn/courses/x86/examples/jump-table.md) (x86-64 assembly), [Binary search](https://asm-editor.specy.app/learn/courses/x86/examples/binary-search.md) (x86-64 assembly), [Print an unsigned number in bases 2 through 36](https://asm-editor.specy.app/learn/courses/x86/examples/number-to-string.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

- `ret`
- `ret 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
        call double
        jmp done

double:
        add rax, rax
        ret                 ; back to the line after the call

done:

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