Try it Live
Run Opcode examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Opcode API.
What Are Opcodes?
Opcodes are single-byte instructions (0x00-0xFF) that tell the EVM what to do. The EVM has ~140 unique opcodes organized by category:- Arithmetic - ADD, MUL, SUB, DIV, MOD
- Logic - AND, OR, XOR, NOT, LT, GT, EQ
- Storage - SLOAD, SSTORE (persistent contract storage)
- Memory - MLOAD, MSTORE (temporary execution data)
- Control Flow - JUMP, JUMPI, JUMPDEST (loops, conditionals)
- Calls - CALL, DELEGATECALL, STATICCALL, CREATE
- System - ADDRESS, CALLER, CALLVALUE, RETURN, REVERT
Stack Machine Architecture
The EVM is a stack machine - all operations push/pop values to/from a runtime stack:- ADD Example
- Stack Visualization
Opcode Categories
Arithmetic Operations
Binary operations pop 2 values, push 1 result:Storage Operations
SLOAD reads from persistent contract storage, SSTORE writes:Memory Operations
MLOAD reads from temporary memory, MSTORE writes:Control Flow
JUMP and JUMPI control program flow. Jump targets must be JUMPDEST (0x5B):External Calls
CALL invokes other contracts:Gas Costs
Every opcode has a base gas cost. Some have dynamic costs:PUSH Instructions
PUSH1-PUSH32 (0x60-0x7F) embed immediate data in bytecode:Stack Depth Limit
The EVM stack has a 1024-item maximum. Stack overflow causes execution to fail:Common Patterns
Function Dispatch
Contracts check function selectors (first 4 bytes of calldata):Storage Access
Reading and modifying storage:Memory Layout
Common memory usage pattern:Complete Example: Return Value
Contract that returns the value 42:Resources
- evm.codes - Interactive opcode reference with gas costs and stack effects
- Ethereum Yellow Paper - Formal EVM specification (Appendix H)
- wolflo/evm-opcodes - Comprehensive opcode gas costs
- Solidity Yul - Low-level EVM assembly language
- EIP-2929 - Access lists (warm/cold gas costs)
- EIP-3855 - PUSH0 instruction (Shanghai hardfork)
Next Steps
- Opcode Overview - Type definition and API reference
- Reference Guide - Complete opcode listing
- Constructors - Parsing and analysis functions
- Validation - Category checks and jump validation
- Utilities - Metadata, disassembly, stack effects

