Instruction set architecture
Introducido
6:22
Arquitectura de computadoras
This course looks at the machine below the program, and how it earns its speed. The first two units are the contract, the instruction set, and the machine that…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| Computer architecture/kəmˈpjuːtə ˈɑːkɪtektʃə/ | The machine below the program. |
| instruction set architecture/ɪnˈstrʌkʃn set ˈɑːkɪtektʃə/ | arquitectura del juego de instrucciones |
| RISC/rɪsk/ | |
| load-store/ləʊd stɔː/ | a processor design in which only load and store instructions access memory; arithmetic works on registers |
| immediate/ɪˈmiːdɪət/ | A constant written inside an instruction itself rather than held in a register. |
| byte-addressable/baɪt əˈdresəbl/ | memory in which every byte has its own address |
| CISC/sɪsk/ | Complex instruction set computer: a design with many, varied instructions, some doing several steps, such as x86. |
| big-endian/bɪɡ enˈdɪən/ | storing the most significant byte of a word at the lowest address |
| little-endian/ˈlɪtl enˈdɪən/ | storing the least significant byte of a word at the lowest address |
| byte addressing |
El contrato
- Arquitectura de computadoras es la máquina debajo del programa. La arquitectura del conjunto de instrucciones (ISA) es su contrato con el software: todo lo que un compilador puede asumir, nada sobre los cables. Dos máquinas con una ISA ejecutan los mismos binarios.
- Nuestra ISA didáctica es RISC en espíritu: instrucciones fijas de 32 bits, carga-almacenamiento (solo
lw/swtocan memoria), 16 registros con R0 hardcodeado a cero.
Tipo R: opcode(4) | rd(4) | rs(4) | rt(4) | shift(4) | funct(8) — 28 bits usados, rellenados con ceros hasta 32. Tipo I: opcode(4) | rt(4) | rs(4) | immediate(16).
The ISA is best described as —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
It states everything software may rely on and nothing about implementation.
Codificar y decodificar
- Codificar
add R3, R1, R2con opcode 1: campos $0001\,0011\,0001\,0010\,0000\,00000001$. Decodificar opcode 2, rt 4, rs 1, inmediato $127$:addi R4, R1, 127. - Un inmediato de complemento a dos de 16 bits abarca de $-32\,768$ a $32\,767$;
addi R2, R0, 40000no puede codificarse y necesita dos instrucciones.


A 16-bit signed immediate can hold —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The range is −32 768 to 32 767; 40 000 needs two instructions.
addi R2, R0, 40000 fits in one instruction of the teaching ISA.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The immediate is a 16-bit two's complement field, so it reaches only $32\,767$. Loading $40\,000$ needs two instructions, for example an upper-half load and an add.
Esta tarjeta se corrigió, por eso aparece en inglés hasta que se actualice su traducción.
What R0 buys
- With byte-addressable 按字节编址 memory and 32-bit words, an aligned
lweffective address is a multiple of 4. A 16-bit signed offset reaches a window of $2^{16}$ bytes = 64 KiB around the base register. addi R0, R0, 0is the standard no-op;add R5, R0, R0sets R5 to zero in one cycle;beq R1, R0, loopcompares with zero without a constant. A fixed zero register removes a whole group of move instructions.
R0 hardwired to zero lets a program —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
add R5, R0, R0 zeroes R5 in one cycle — no move-immediate needed.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Addressing modes and branch reach
- There are four ways to name an operand:
| Mode: where the operand is | Example |
|---|---|
| Register: in a register | add R3, R1, R2 |
| Immediate: in the instruction | addi R4, R1, 127 |
| Base + offset: memory at R1 + 8 | lw R4, 8(R1) |
| PC-relative: a branch target | beq R1, R2, -3 |
- A branch's immediate counts instructions, not bytes: target $= \text{PC} + 4 + 4 \times \text{imm}$. A
beqat $0x100$ with imm $-3$ goes to $0x104 - 12 = 0xF8$. - With a 16-bit immediate, a branch reaches about $\pm 32\,768$ instructions ($\pm 128$ KiB). CISC 复杂指令集 machines such as x86 use instructions of 1 to 15 bytes and allow memory operands. RISC keeps decoding simple, and that makes pipelining easy.
A beq sits at address 512 with immediate 5. What is the target address (in decimal)?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
PC + 4 = 516, plus 4 x 5 = 20, gives 536.
In a load-store ISA, which instruction may read memory?
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Only loads and stores touch memory; arithmetic works on registers.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Which byte comes first: endianness
- A 32-bit word fills four byte addresses. Store
0x12345678at0x100: a big-endian 大端 machine puts0x12at0x100; a little-endian 小端 machine, such as x86 and most RISC-V systems, puts0x78there. - Inside one machine you never see it. It causes bugs when bytes cross a boundary: a file, a network packet (network order is big-endian), or a pointer cast to
char*.
0x12345678 stored at 0x100 on a little-endian machine. The byte at 0x100 is:
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Little-endian stores the least significant byte at the lowest address.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Worked example: decode a branch target
- A
beqat0x200holds immediate 立即数 $5$. The target is $\text{PC} + 4 + 4 \times 5 = 0x204 + 20 = \mathbf{0x218}$, five instructions after the next one. - Going backwards needs a negative immediate. To reach
0x1F0from0x200, $\text{imm} = (0x1F0 - 0x204)/4 = -5$. Loops are backward branches, so their immediates are negative.
A beq at 0x200 with immediate 5 branches to:
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
$0x204 + 4 \times 5 = 0x218$.
Immediate for a beq at 0x200 that targets 0x1F0?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$(0x1F0 - 0x204)/4 = -20/4 = -5$.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Marks that slip away
- Word index as byte offset. With byte addressing 字节编址, word $3$ of an array is at offset $12$, not $3$.
- Forgetting the immediate's range. A 16-bit signed field stops at $32\,767$; a larger constant needs two instructions.
- Counting a branch from itself. The target is $\text{PC} + 4 + 4 \times \text{imm}$: the offset counts words from the next instruction.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
Recap
- The ISA is the contract between hardware and software; one ISA runs the same binaries on different hardware.
- Fixed 32-bit RISC formats, load-store 加载存储, R0 always zero.
- A 16-bit immediate runs from $-32\,768$ to $32\,767$; branch target $= \text{PC} + 4 + 4 \times \text{imm}$.
¿Qué salió mal? Solo el equipo del sitio ve esta información.