Machine Instructions, Addressing Modes, RISC and CISC
In questa pagina 5
This note collects the architectural view of the instruction set; the concrete 16-bit example with opcodes, decoder and control words is in Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle ControlThe 16-bit instruction word has an opcode of 7 bits plus register fields (DR, SA, SB or an immediate OP) or a branch format with a 6-bit PC-relative signed offset; the instruction set is load/store with ADD, SUB, logic, shifts, LDI, ADI, LD, ST, BRZ, BRN and JMP. In the single-cycle computer (separate instruction and data memories) a combinational instruction decoder derives MB, MD, RW, MW, PL, JB, BC from bits 15, 14, 13 and 9 and FS from bits 12 to 9, and the clock period is the sum of the delays on the critical path (9.8 ns in the example). In the multi-cycle computer (one memory) an instruction register, internal registers R8 to R15 and a sequential decoder are needed: fetch (INF) plus one or more execution states.Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle Control →, and the datapath in Simple Computer - Datapath, ALU and Register FileA simplified but fully working computer has a datapath, a control unit and a memory; the datapath is a register file with two read ports and one write port, a MUX B (register or constant), a function unit made of ALU plus shifter, and a MUX D (result or data from memory), and it reports the status bits V, C, N, Z. The ALU joins an arithmetic circuit (an adder with input logic on B and a carry-in) and a logic circuit through a MUX, and the 15 microoperations are selected by a 4-bit code FS, so the datapath control word is 16 bits wide.Simple Computer - Datapath, ALU and Register File →.
Machine instructions
Definition (machine instruction). A machine instruction is a set of bits that completely specifies an operation. It is divided into fields: the opcode (the operation) and the operands (registers, constants or memory), indicated explicitly with dedicated bits or implicitly inside the opcode. The assembler translates the symbolic mnemonic (ADD, LD, BRZ, ...) into binary.
Example. With a 7-bit opcode there are operations; with 32 registers, 5 bits identify a register.
Instruction classes of the example machine:
- register operations (move, arithmetic, logic, shift): operands and result in registers;
- immediate operations (LDI, ADI): one operand is a constant inside the instruction, extended with zeros (zero fill) or with the sign bit (sign extension);
- memory access: LD () and ST ();
- control transfer: conditional branches (BRZ, BRN) and the jump (JMP).
In a load/store architecture LD and ST are the only instructions that access data memory; all others work on registers. This needs many registers, to avoid too many loads and stores (which take several cycles).
Addressing modes
Definition (addressing mode). The way an instruction specifies where its operand is, or where the next instruction is.
The four modes of the RISC machine:
| mode | operand or target | where it is used |
|---|---|---|
| register | the operand is in a register named by a field | arithmetic, logic, shift |
| register indirect | the register holds the memory address of the operand: | only LD and ST |
| immediate | the operand is a constant in the instruction | LDI, ADI |
| relative | the target is with a signed offset (two's complement) | branches |
The jump is the register variant: , with a wider range than a PC-relative branch, whose offset is only 6 bits. A branch copes with distances both forwards and backwards thanks to sign extension of the offset.
The double indirect load (two memory accesses) is a CISC-style mode: it needs 3 cycles on the multi-cycle machine.
RISC architecture
Definition (RISC). A Reduced Instruction Set Computer is optimised for simple instructions: simpler and faster hardware, with complex operations built by the compiler from simple instructions. Features:
- load/store memory access;
- few, simple addressing modes (the four above);
- a single instruction length;
- elementary operations, executable in one pass through the pipeline.
Registers: 32 registers, many because every operation uses register operands only. R0 is special: it reads as and discards the result when used as destination.
Format (32 bits): 7-bit opcode (128 operations), SA and SB source registers, DR destination; for branches the target is PC + offset (two's complement). Three types: three registers, two registers + immediate, branch. Many operations accept an immediate operand, to reduce memory accesses.
Datapath changes for the pipelined RISC CPU: a register file with , built with latches allowing write in the first half of the cycle and read in the second; a 32-bit ALU and a barrel shifter. The barrel shifter does left and right shifts of positions with one right rotation, prepending zeros to the operand (right: positions; left: positions on an operand extended to 64 bits).
CISC architecture
Definition (CISC). A Complex Instruction Set Computer has complex instructions, very hard or impossible to execute in one cycle or one pipeline pass. Features: more addressing modes, variable instruction length, more sophisticated branches.
Combined CISC-RISC organisation: a RISC core for simple instructions plus a microprogrammed control for complex ones, with temporary registers. The microprogrammed control is a state machine whose combinational logic is a ROM (the microprogram): a complex instruction is a sequence of microinstructions, so it takes several clock cycles. It does not make instructions of any complexity run in one cycle.
Changes with respect to RISC: branch format comparing two registers; condition codes (, , ...) held in a condition code register; temporary registers; larger constant unit; stall signals on PC and IR; a MUX choosing between simple and microprogrammed instructions.
| RISC | CISC | |
|---|---|---|
| instructions | simple, one per cycle or pass | complex, several cycles |
| length | fixed | variable |
| memory | load/store | operands also in memory |
| addressing | few modes (4) | many modes |
| control | hardwired (decoder) | microprogrammed (ROM) |
| registers | many (32) | fewer, with temporaries |
Common mistakes
- Treating the load/store address as an instruction field: it is the content of a register.
- Saying a microprogrammed unit runs any instruction in one cycle: it needs several.
- Forgetting that R0 discards writes.
Versione ripasso
- Instruction: opcode plus operand fields (explicit or implicit); the assembler turns mnemonics into binary. 7-bit opcode: 128 operations; 32 registers: 5 bits.
- Load/store: only LD and ST access data memory; all other operations use registers, hence many registers.
- Addressing modes (RISC, 4): register; register indirect (, LD/ST only); immediate (zero fill or sign extension); relative (, two's complement). JMP: , wider range than a 6-bit relative branch.
- RISC: simple instructions, one length, one pipeline pass, 4 modes, 32 registers with R0 (writes discarded); register file with write in the first half-cycle and read in the second; barrel shifter does left/right shifts of positions with right rotation of an operand extended to 64 bits.
- CISC: complex instructions, many modes, variable length, microprogrammed control (state machine whose logic is a ROM), several cycles, condition code register, temporary registers. Double indirect load is CISC-style.
- Comparison: RISC fixed length, load/store, 32 registers, hardwired; CISC variable length, memory operands, fewer registers, microprogrammed.
- Mistakes: address read as an instruction field; microprogram taken as one-cycle execution; R0 writes forgotten.