You can add a card, copy a nearby card or exchange the top card with another one.
SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.PUSH1 reads its next byte as an immediate value and places two on the stack. The next instruction begins at byte two.The next PUSH1 places three above two. Stack order matters for operations that are not commutative.ADD consumes the top two values and pushes five. The next instruction is STOP at byte five; no storage write is implied by ADD.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Push an immediate value
PUSH1 through PUSH32 take that many immediate bytes from code and push a word. PUSH0 pushes zero without any following immediate data bytes.
Duplicate without consuming
DUP1 copies the top item. DUP2 copies the next item down. The original value remains in place while the copied value becomes the new top.
Swap with a nearby item
SWAP1 exchanges the top item and the item immediately below it. Numbered swap operations access a limited range rather than arbitrary stack positions.
Keep enough operands
A duplication or swap requires the referenced depth to exist. Stack underflow is a real execution failure, not an automatic request to fill missing entries with zero.
Trace the idea
[2, 3]
DUP1 → [2, 3, 3]
SWAP2 → [3, 3, 2]
Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.