Instruction positions are byte offsets into the executing code.
LET’S PICTURE IT
A bookmark tracks the current position in a machine-readable instruction strip.
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.
Count code bytes
The program counter identifies a byte position in the current code. It is not a source line number or the number of instructions already executed.
Skip immediate bytes
PUSH1 consumes one following immediate byte. PUSH2 consumes two. Those data bytes are part of the instruction encoding rather than separate executed opcodes.
Account for control flow
A valid jump can move execution to another permitted instruction position. A trace must follow the actual path rather than simply scanning every code byte once.
Relate positions carefully
Source maps can connect compiled positions to source ranges, but compiler transformations complicate the relationship. Preserve the exact compiled bytecode when debugging.
Trace the idea
PC 0: PUSH2 0x1234
PC 3: POP
PC 4: STOP
Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.
QUICK CHECK · NO PRESSURE
After PUSH2 with two immediate bytes at PC 0, where is the next instruction?
One opcode byte plus two immediate bytes occupy three bytes.