In this track: Connect everything together
advanced · 6 MIN READ

Trace a tiny stack program

Decode immediate bytes and record each stack transition.

LET’S PICTURE IT

A calculator worksheet should show the intermediate values and the actual output behavior.

SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
Watch a stack machine execute a tiny programProgram→ PUSH1 0x02PUSH1 0x03ADD · STOPStackEmptyPC = 0A fixed local model; not a complete EVM implementationPUSH1 0x02Push immediate 2Next PC = 2Stack · top first2PUSH1 occupies one opcode byte plus one immediate bytePUSH1 0x03Push immediate 3Next PC = 4Stack · top first32The first value is below the most recently pushed valueADD3 + 2 = 5Next: STOP at PC 5Stack5No automatic SSTOREStack, memory and persistent storage are different locations

The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Parse the bytecode

Use 600260030100. The two 60 bytes are PUSH1 opcodes, each followed by one immediate value byte. The next instructions are ADD and STOP.

Track the program counter

The instruction positions are zero, two, four and five. Counting every byte as an instruction would incorrectly execute the immediate data.

Track the stack convention

Write bottom first and top last: empty, then [2], then [2,3], then [5]. State the convention so another reference can be compared correctly.

Separate result and return bytes

STOP succeeds with no explicit output. The remaining stack value is not automatically returned to a caller or written to persistent storage.

Your acceptance target

bytecode: 0x600260030100
PCs: 0, 2, 4, 5
final stack: [5]
outcome: success
return bytes: empty

Use only local examples and public sample addresses. State the assumptions and limits alongside the result.

QUICK CHECK · NO PRESSURE

Does this program return ABI-encoded 5?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.