0Pricing
Web3 & DApp Development Fundamentals · 课时

操作码

底层操作

操作码 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The EVM Instruction Set

At its lowest level, the EVM runs a sequence of opcodes — single-byte instructions that each do one thing.

Understanding opcodes reveals what your Solidity actually does and where gas goes.

What Is an Opcode?

An opcode (operation code) is a one-byte command the EVM executes. Examples include ADD, MUL, PUSH1, SLOAD, and JUMP.

Each opcode has a name, a numeric value, and a fixed gas cost.

0x01 = ADD
0x02 = MUL
0x60 = PUSH1
0x54 = SLOAD
0x56 = JUMP

Stack Manipulation Opcodes

Opcodes like PUSH, POP, DUP, and SWAP manage the stack.

PUSH adds a value, POP removes one, DUP duplicates an item, and SWAP exchanges two stack positions.

PUSH1 0x0A   // [10]
DUP1         // [10, 10]
PUSH1 0x14   // [10, 10, 20]
SWAP1        // [10, 20, 10]

Arithmetic Opcodes

Arithmetic opcodes pop operands and push results: ADD, SUB, MUL, DIV, and MOD.

All math is done on 256-bit unsigned integers (with signed variants available).

PUSH1 0x09   // [9]
PUSH1 0x04   // [9, 4]
SUB          // [5]   (9 - 4)

Comparison and Logic

Opcodes like LT, GT, EQ, AND, OR, and ISZERO handle comparisons and bitwise logic.

They push 1 for true and 0 for false, which control flow then uses.

Memory and Storage Opcodes

Data movement opcodes touch the costly locations:

  • MLOAD / MSTORE — read/write memory
  • SLOAD / SSTORE — read/write storage

SSTORE is one of the most expensive opcodes.

Control Flow Opcodes

JUMP and JUMPI (conditional jump) move execution to a JUMPDEST marker.

This is how the EVM implements loops and if-statements at the bytecode level.

PUSH1 0x10   // jump target
JUMPI        // jump if top of stack != 0
// ... at offset 0x10:
JUMPDEST     // valid landing spot

Environment Opcodes

Opcodes like CALLER, CALLVALUE, ADDRESS, and TIMESTAMP expose context.

For example, CALLER pushes the address that initiated the call (this is what msg.sender compiles to).

Gas Cost per Opcode

Every opcode has a defined gas cost. Cheap ones like ADD cost 3 gas; expensive ones like SSTORE cost up to 20000.

The total gas of a transaction is the sum of all opcodes it executes.

ADD    -> 3 gas
MLOAD  -> 3 gas
SLOAD  -> 2100 gas
SSTORE -> up to 20000 gas

From Solidity to Opcodes

The Solidity compiler turns each high-level statement into many opcodes.

A single uint x = a + b; becomes PUSH, PUSH, ADD, and an MSTORE or SSTORE depending on where x lives.

Putting It Together

Opcodes are the EVM's atomic instructions for stack, arithmetic, logic, memory, storage, control flow, and environment.

Each carries a gas cost, and your Solidity ultimately becomes a stream of them.

Quick Check

Test your opcode knowledge.

Recap: Opcodes

You learned that:

  • Opcodes are one-byte EVM instructions
  • They cover the stack, arithmetic, logic, memory, storage, control flow, and environment
  • SSTORE is among the most expensive
  • Solidity compiles into many opcodes

Next: accounts and state.

常见问题解答

「操作码」课时是免费的吗?

是的 — 「操作码」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。

「操作码」这节课中我会学到什么?

底层操作 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Web3 & DApp Development Fundamentals 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「操作码」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?

能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Ethereum 虚拟机
  2. 存储、内存与栈
  3. 操作码
  4. 账户与状态
← 返回 Web3 & DApp Development Fundamentals