機械命令
導入済み
5:52
コンピュータシステム基礎
This course follows a program from a single bit to a running process. The first two units are the alphabet: how bits encode data, and how logic gates compute…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| instructions/ɪnˈstrʌkʃnz/ | |
| immediate/ɪˈmiːdɪət/ | 即値 |
| addressing mode/əˈdresɪŋ məʊd/ | アドレス指定モード |
| RISC/rɪsk/ | |
| CISC/sɪsk/ | |
| countdown loop | |
| base register | |
| Base address/beɪs əˈdres/ | |
| loop counter/luːp ˈkaʊntə/ |
One line of C, several machine steps
- The line
a[i] = a[i] + 1looks like one action. The processor carries it out as a short list of tiny instructions 指令. - Every compiler targets this small vocabulary, and every speed question ends here. This lesson reads it.
The instruction kinds
add rd, rs1, rs2adds two registers;addiadds an immediate 立即数, a constant written inside the instruction.lw(load word) andsw(store word) move data between memory and registers;beqandbnecompare two registers and branch.
各命令とそれが行う操作を対応させよ。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
4種類の命令は、演算、メモリ操作、制御を網羅する。
Addressing modes
- The addressing mode 寻址方式 says where an operand lives: in a register, in the instruction (immediate), or in memory at base + offset.
lw R1, 8(R2)reads memory at address R2 + 8. The 8 is an offset, not the value 8.

lw R1, 0(R2) において 0 は —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
アドレス = R2 + 0。これはベース+オフセット addressing である。
R2 が 400 を保持しているとき、lw R1, 12(R2) はどのメモリアドレスを参照するか?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
ベース+オフセット = 400 + 12 = 412。
Why RISC only loads and stores
- In RISC 精简指令集 designs, only
lwandswtouch memory; arithmetic works register to register. One simple shape decodes fast and fits a pipeline well. - CISC 复杂指令集 designs let arithmetic read memory directly. The code is shorter but harder to pipeline: more instructions against faster instructions.
RISC ロード/ストア設計では、add 命令の入力の一方をメモリからそのまま受け取ることができる。
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
メモリにアクセスするのは lw と sw のみである。add はレジスタのみで動作する。
A loop is two instructions
loop: addi R1, R1, -1thenbne R1, R0, loop. R0 always holds 0, so this means "subtract 1, and jump back unless R1 is now 0".- This pair can implement a countdown loop 倒计数循环 whose body executes a known positive number of times; a general
whileloop needs code for its own condition, including an initial test when necessary.
カウントダウンを行うC言語のwhileループは、以下のペアにコンパイルされる —
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
各パスあたり2指令 — 減算、ゼロとの比較、再帰跳躍。
R1は6から始まります。ループ内では、addi R1, R1, -1 の後、bne R1, R0, loop となります。bne は何回バックジャンプしますか?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
本体は6回実行されます。6回目のパス終了後に R1 は0 となるため、最終の bne は通過し、バックジャンプは5回行われます。
Arrays are address arithmetic
- Element
a[i]lives at base + $i$ × element size. With 4-byte words,a[5]is at base + 20. - So a pointer is just a base register 基址寄存器, and indexing is a multiply and an add.
4バイト整数の配列がアドレス2000から開始されています。a[7] はどのアドレスにありますか?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
2000 + 7 × 4 = 2028.
Worked example: a[i] = a[i] + 1
- Base address 基地址 in R2, $i = 3$, 4-byte words: the offset is $3 \times 4 = 12$, so the element is at R2 + 12.
lw R5, 12(R2)loads it;addi R5, R5, 1adds one;sw R5, 12(R2)stores it back: load, add, store.
a[i] = a[i] + 1 の機械語ステップを正しい順序に並べ替えてください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
アドレス、ロード、加算、ストア — インデキシングはスケーリングされたアドレス演算です。
Worked example: counting a loop
- R1 starts at 3. Pass 1: R1 becomes 2,
bnejumps back. Pass 2: R1 becomes 1, jumps back. Pass 3: R1 becomes 0, falls through. - The body runs 3 times and
bnejumps back only twice.
Three common slips
- Reading
0(R2)as the value 0. It is offset 0 from the address in R2. - Forgetting to set the loop counter 循环计数器. The loop then runs from whatever R1 held.
- Using $i$ as the byte offset. Scale it by the element size: $4i$ for 4-byte words.
Recap
- Six instructions; memory only through load and store, at base + offset:
| Instruction | Does |
|---|---|
add |
register + register |
addi |
register + a constant |
lw R1, 8(R2) |
load from R2 + 8 |
sw R1, 8(R2) |
store to R2 + 8 |
beq, bne |
branch if equal, if not equal |
- RISC 精简指令集 trades more instructions for simpler, faster ones that pipeline well.
- A while loop is decrement and branch;
a[i]is base + $i$ × size.
何が問題でしたか?この内容はサイトの運営チームだけが確認します。