enterq

Create 64-bit stack frame

Creates a 64-bit stack frame for a procedure call: pushes rbp, sets rbp to rsp, and reserves the local bytes.

x86-64 and later

Intel's reference: ENTER

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

Forms

  • enterq ,
  • enterq

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:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        enterq 5, 5

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