# `enter`

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

**Create stack frame**

Category: Stack

Constructs a stack frame for a high-level language procedure call, saving rbp and reserving space for its local variables.

186 and later

[Intel's reference: ENTER](https://intel.github.io/SDM/instruction/ENTER.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

- `enter imm16, imm8`
- `enter imm16`

## Operands

- `imm16`: A 16-bit immediate, `-32768` to `65535`.
- `imm8`: An 8-bit immediate, `-128` to `255`. Instructions that sign-extend it to a wider operand interpret the byte as `-128` to `127`; shift counts do not use this sign extension.

## Description

The first immediate is an unsigned 16-bit byte count for local storage; the second is a nesting level whose low five bits are used (0–31). NASM also accepts a single operand, with nesting level zero.

In 64-bit code, `enter 32, 0` has the frame-building effect of:

```x86
push rbp
mov rbp, rsp
sub rsp, 32
```

Unlike the `sub` in that sequence, `enter` leaves flags unchanged. The saved frame pointer is at `[rbp]`, and local storage lies below `rbp`. Nonzero nesting levels also copy enclosing frame pointers in 8-byte slots and push the new frame pointer. `enterq` explicitly selects this 64-bit frame size; `leave` can dismantle the frame.

## Example

```x86
global _start

section .text
_start:
        enter 16, 0         ; a 16 byte frame, no nesting
        mov qword [rbp - 8], 12
        leave               ; undoes it

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