ret
Near return, default size
Pops the 8-byte return address from the stack into rip and transfers control to it.
8086 and later
Used in
- The x86-64 instruction setx86-64 assembly
- call, ret and the System V conventionx86-64 assembly
- SSE2 scalar and packed arithmeticx86-64 assembly
- Interrupts, exceptions and signalsx86-64 assembly
- A subroutine with its arguments in registersx86-64 assembly
- Stack arguments and a stack framex86-64 assembly
- Recursion: factorial and Fibonaccix86-64 assembly
- A jump tablex86-64 assembly
- Binary searchx86-64 assembly
- Print an unsigned number in bases 2 through 36x86-64 assembly
CFPFAFZFSFDFOF –––––––
- Changes no flag
Forms
retret
Operands
imm16- An unsigned 16-bit byte count,
0to65535, added to the stack pointer after the return address is popped.
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.
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