enter

Create stack frame

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

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • enter ,
  • enter

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.

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:

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.

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