CPU Structure and Registers
In questa pagina 7
In questa pagina 4
Architecture and organization
Definition (architecture and organization).
Architecture Organization What it is attributes visible to the programmer that affect the logical execution of a program the operational units and their interconnections that implement the architecture Examples instruction set, data width, addressing modes, I/O mechanisms control signals, memory technology, peripheral interfaces, circuits used Typical question is there a multiply instruction? is multiplication done by a dedicated circuit or by repeated additions?
A processor family shares one architecture with different organizations (faster or cheaper): a program written for one model runs on the others. Backward compatibility weighs heavily on design choices (x86 from the late 1970s to today). A microcontroller or a DSP is a processor core plus memory and peripherals on one chip; what follows describes the core.
Stored-program (von Neumann) machine
Definition (von Neumann machine). Early machines were programmed by rewiring (hardwired program). The von Neumann idea is a general hardware that performs different operations according to the control signals it receives, with these commands written as instructions stored in memory together with the data.
- data and instructions share the same memory, readable and writable;
- memory is addressed by position, regardless of content;
- instructions execute in sequence, unless an explicit jump occurs.
Example. In the IAS machine a 40-bit word holds two 20-bit instructions (8-bit opcode + 12-bit address): words are all addressable.
The separate-memory alternative is the Harvard architecture (distinct instruction and data memories/buses). It is used today, for example, for the L1 instruction and data caches.
Internal components
The CPU must fetch instructions, interpret them, fetch data, process them and write results (see Fetch-Execute Cycle and DatapathThe registers PC, IR, MAR and MBR, the fetch and execute phases and the four kinds of action, the full instruction-cycle state diagram with interrupt check, a worked accumulator-machine example, and the datapath of a simple RISC core with single-cycle and multicycle timing.Fetch-Execute Cycle and Datapath →). It needs a small, very fast internal memory: the registers. Components:
- ALU (Arithmetic Logic UnitRole of the ALU, its inputs and the N Z C V flags, the 1-bit ALU built from AND, OR, a full adder and a multiplexer, the N-bit ALU with subtraction, NOR, set-less-than, zero and overflow detection, comparators, bus sharing with tri-state outputs, and the other computation units.Arithmetic Logic Unit →): performs the operations;
- control unit (Hardwired and Microprogrammed ControlWhat the control unit does, control signals of a single-cycle datapath with the table for each instruction class, hardwired control (combinational or finite-state machine), microprogrammed control (control memory, horizontal and vertical microinstructions, microsequencer), and a comparison.Hardwired and Microprogrammed Control →): coordinates and times everything;
- register file;
- internal bus connecting them.
User-visible registers
The "programmer" is whoever writes assembly, or the compiler.
| Type | Use |
|---|---|
| general purpose | operands, results, addresses |
| data | data only (in some architectures) |
| address | pointers: segment base registers, index registers, stack pointer |
| condition codes (flags) | bits set by the ALU, read by conditional instructions |
Property (number of registers and instruction bits). More registers mean fewer memory accesses, but more instruction bits to name them ( bits per operand with 16 registers, with 32) and more state to save at every call or interrupt. RISC machines typically have 16-32 registers (Instruction Set ArchitectureWhat an instruction set defines, the elements of an instruction, operand and operation types, 0-, 1-, 2- and 3-address machines on the same calculation, load/store architectures, and the RISC and CISC design philosophies with register windows and register allocation by graph coloring.Instruction Set Architecture →); 32-bit ARM has 16, MIPS 32.
Example: evaluating with variables in memory. With 6 free registers each variable is loaded once; with 4 registers some intermediate results must be saved to memory and reloaded, giving more loads and stores.
Property (register width and address space). Address registers must hold a whole address: 32-bit registers address bytes GB, 64-bit registers .
Control and status registers
Usually not directly accessible: PC, IR, MAR, MBR (defined in Fetch-Execute Cycle and DatapathThe registers PC, IR, MAR and MBR, the fetch and execute phases and the four kinds of action, the full instruction-cycle state diagram with interrupt check, a worked accumulator-machine example, and the datapath of a simple RISC core with single-cycle and multicycle timing.Fetch-Execute Cycle and Datapath →) and the program status word (PSW; called CPSR in ARM).
Definition (PSW). Typical contents:
- flags: N (negative: most significant bit of the result), Z (zero), C (carry), V (overflow), see Binary ArithmeticBinary addition and two's complement subtraction, overflow for unsigned (carry) and signed (sign change) numbers, the N Z C V flags, multiplication by shifts and additions, Booth's algorithm with a worked example, division, and logical, arithmetic and rotate shifts.Binary Arithmetic →;
- interrupt enable bits;
- supervisor bit (privileged mode): says whether the CPU is running operating-system code. Only in this mode are privileged instructions allowed (memory management, I/O, changing the PSW itself); a user program attempting them raises an exception.
Example. At 8 bits in two's complement, gives , , , .
Segmentation
In some architectures (x86) memory is logically divided into segments (code, data, stack). Addresses within a segment start from 0 (logical address); the linear address is the segment base, held in a segment register, plus the logical address. ARM and MIPS use a linear address space, with protection left to virtual memory.
Common mistakes
- Treating the PC as a general register: in MIPS it is not; in ARM it is
r15, and writing to it is a jump. - Thinking a user program can change the supervisor bit: only an interrupt or an operating-system call changes it.
- Calling the memory technology or the adder type "architecture": these are organization choices.
- Thinking von Neumann means "separate program memory": it is the opposite (separation is Harvard).
Versione ripasso
Architecture = what the programmer sees (ISA, data width, addressing modes, I/O); organization = how it is built (control signals, memory technology, circuits). A family shares the architecture.
Stored program
von Neumann: instructions and data in the same memory, addressed by position, executed in sequence unless jumped. Harvard: separate instruction and data memories (used today for L1 caches).
Components
ALU (Arithmetic Logic UnitRole of the ALU, its inputs and the N Z C V flags, the 1-bit ALU built from AND, OR, a full adder and a multiplexer, the N-bit ALU with subtraction, NOR, set-less-than, zero and overflow detection, comparators, bus sharing with tri-state outputs, and the other computation units.Arithmetic Logic Unit →), control unit (Hardwired and Microprogrammed ControlWhat the control unit does, control signals of a single-cycle datapath with the table for each instruction class, hardwired control (combinational or finite-state machine), microprogrammed control (control memory, horizontal and vertical microinstructions, microsequencer), and a comparison.Hardwired and Microprogrammed Control →), register file, internal bus; see Fetch-Execute Cycle and DatapathThe registers PC, IR, MAR and MBR, the fetch and execute phases and the four kinds of action, the full instruction-cycle state diagram with interrupt check, a worked accumulator-machine example, and the datapath of a simple RISC core with single-cycle and multicycle timing.Fetch-Execute Cycle and Datapath →.
Registers
- User-visible: general, data, address (base, index, stack pointer), flags.
- More registers: fewer memory accesses, but more bits in the instruction (16 registers: 4 bits, 32: 5), more state to save per call or interrupt. RISC 16-32 (Instruction Set ArchitectureWhat an instruction set defines, the elements of an instruction, operand and operation types, 0-, 1-, 2- and 3-address machines on the same calculation, load/store architectures, and the RISC and CISC design philosophies with register windows and register allocation by graph coloring.Instruction Set Architecture →); ARM 16, MIPS 32. 32-bit address registers reach 4 GB.
- Control/status: PC, IR, MAR, MBR, PSW (CPSR in ARM): flags N, Z, C, V (Binary ArithmeticBinary addition and two's complement subtraction, overflow for unsigned (carry) and signed (sign change) numbers, the N Z C V flags, multiplication by shifts and additions, Booth's algorithm with a worked example, division, and logical, arithmetic and rotate shifts.Binary Arithmetic →), interrupt enable, supervisor bit (privileged instructions allowed only in supervisor mode, otherwise exception).
Segmentation
x86: linear address = segment base + logical address. ARM and MIPS: linear space.
Common mistakes: the PC is not a general register (ARM r15: writing it is a jump); only an interrupt or system call changes the supervisor bit.