# `call`

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

**Call procedure**

Category: Control flow

Calls a subroutine by pushing the return address onto the stack (with cs for a far call), then jumps to the given address.

8086 and later

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

Used in: [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), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/x86/examples/drawing-on-the-screen.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

- `call near imm64`
- `call near r/m64`
- `call far mem` (32, 64)
  - `call mem32`: 386 and later
  - `call mem64`

## Operands

- `imm64`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. In 64-bit mode the encoded displacement is signed 32-bit, `-2147483648` to `2147483647`, even though the target address is 64-bit.
- `r/m64`: A 64-bit general-purpose register or quadword in memory, for example `rax` or `qword [rsi]`.
- `mem`: A memory location addressed with square brackets, for example `[rbx+8]` or `[label]`.

## Description

An ordinary near call in 64-bit code pushes an 8-byte return address using `rsp`; `ret` returns to that address.

`call routine` names a target address or label. NASM calculates a signed 32-bit displacement from the end of the call, so the target must be within that range (about ±2 GiB). The source operand is the target, not a displacement to add yourself. There is no direct near call with an embedded absolute 64-bit target.

`call rax` takes the full target address from `rax`. `call [pointer]` reads an 8-byte target address from memory. These indirect near calls can reach targets beyond the relative displacement range.

A far call also changes `cs`. Its memory pointer stores an offset followed by a 16-bit segment selector: `word`, `dword` and `qword` far pointers have 16-, 32- and 64-bit offsets, for totals of 4, 6 and 10 bytes. Immediate `segment:offset` calls are unavailable in 64-bit mode. Far transfers depend on valid operating-system segment descriptors and are not ordinary Linux function calls.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        call double         ; pushes the return address and jumps
        jmp done

double:
        add rax, rax
        ret                 ; pops it and comes back

done:

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