Instrucciones de máquina
Introducido
5:52
Fundamentos de sistemas informáticos
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…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| instructions/ɪnˈstrʌkʃnz/ | |
| immediate/ɪˈmiːdɪət/ | |
| addressing mode/əˈdresɪŋ məʊd/ | |
| RISC/rɪsk/ | |
| CISC/sɪsk/ | CISC: conjunto de instrucciones complejo |
| 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.
Asocia cada instrucción con lo que hace.
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
Cuatro tipos de instrucciones cubren aritmética, memoria y control.
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.

En lw R1, 0(R2), el 0 es —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Dirección = R2 + 0. Esto es direccionamiento base más desplazamiento.
R2 contiene 400. ¿Qué dirección de memoria lee lw R1, 12(R2)?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
Base + desplazamiento = 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.
En un diseño RISC de carga/almacenamiento, add puede tomar uno de sus inputs directamente desde la memoria.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Solo lw y sw acceden a la memoria. add opera solo en registros.
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.
Un bucle while en C que cuenta hacia abajo se compila al par —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Dos instrucciones por paso: decremento, comparación con cero, salto atrás.
R1 comienza en 6. El bucle es addi R1, R1, -1 seguido de bne R1, R0, loop. ¿Cuántas veces salta bne atrás?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
El cuerpo se ejecuta 6 veces. Después del sexto paso, R1 es 0, por lo que el último bne no salta; salta atrás 5 veces.
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.
Un array de enteros de 4 bytes comienza en la dirección 2000. ¿En qué dirección se encuentra a[7]?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
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.
Ordena los pasos de máquina de a[i] = a[i] + 1.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
Dirección, carga, suma, guarda: el indexado es aritmética de direcciones escalada.
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.
¿Qué salió mal? Solo el equipo del sitio ve esta información.