x86 Stack Emulator

32-bit · Intel syntax · watch ESP, EBP and EIP move

GitHub

New to the stack? Start here

📚 What is the stack?

A part of memory that works like a pile of plates: you only add (push) or remove (pop) at the top. Last in, first out.

⬇ It grows downward

On x86 the top of the stack has the lowest address. push makes ESP smaller, pop makes it bigger. In the view, the newest value is at the bottom, next to the ESP arrow.

🧭 Three key registers

ESP points at the top of the stack.
EBP is the fixed anchor of the current function.
EIP is the address of the next instruction.

📞 call & ret

call f pushes the return address (where to come back) and jumps to f. ret pops it and jumps back. Overwrite it and the program goes somewhere else!

🧱 One function's frame

higher addresses
[ebp+12]  argument #2
[ebp+8]   argument #1
[ebp+4]   return address
[ebp]     saved EBP      ◀ EBP
[ebp-4]   local variable
[ebp-8]   local variable ◀ ESP
lower addresses

▶ Try it

Pick an example, press Step ▶ and read What just happened. ◀ Back undoes a step. Hover over anything for a hint.

Code

Stack (high addresses on top, grows ↓ toward ESP)

current function return address saved EBP argument free overwritten
pointersaddressoffsetvalueasciiwhat is it

Registers

Stack playground

Run single instructions by hand. EIP is not advanced.

What just happened

    Instruction reference & syntax

    Stack & control flow

    push xESP −= 4; [ESP] = x
    pop rr = [ESP]; ESP += 4
    call fpush next EIP; jmp f
    ret [n]pop EIP; ESP += n
    leavemov esp, ebp; pop ebp
    jmp lEIP = l
    je jne jl jg jle jge jb ja jbe jae js jns (+ aliases)conditional jumps
    hlt, nopstop / do nothing

    Data & arithmetic

    mov d, sd = s
    lea r, [addr]r = address (no memory read)
    add sub and or xord = d op s, sets flags
    cmp testsub / and, flags only
    inc dec neg notunary
    shl shr sarshifts (imm or cl)
    imul r, s [, imm]signed multiply
    xchg a, bswap

    Syntax

    • Registers: eax ebx ecx edx esi edi ebp esp, bytes al ah bl …
    • Numbers: 42, -8, 0x1f, 1fh, 0b101, 'A'
    • Memory: [ebp-8], [esp+4], [eax+ecx*4+8]
    • Size: dword [ebp-4] / byte ptr [edi] (default dword)
    • Labels: name:, local .loop:; execution starts at main
    • Comments: ; or #
    • Only the stack () is mapped memory. Anything else faults.
    • Keys: Ctrl+Enter assemble, → step, ← back.