Instruction sets At the hardware level, processors contain a number of separate areas of circuitry, or "units", that perform different tasks. Commonly found units include the
arithmetic logic unit (ALU) which performs instructions such as addition or comparing two numbers, circuits for reading and writing data to external memory, and small areas of onboard memory to store these values while they are being processed. In most designs, additional high-performance memory, the
register file, is used to store temporary values, not just those needed by the current instruction. To properly perform an instruction, the various circuits have to be activated in order. For instance, it is not possible to add two numbers if they have not yet been loaded from memory. In
RISC designs, the proper ordering of these instructions is largely up to the programmer, or at least to the
compiler of the
programming language they are using. So to add two numbers in memory and store the result in memory, for instance, the compiler may output instructions to load one of the values into one register, the second into another, perform the addition function in the ALU, putting the result into a register, and then store that register into memory. Using the variation of the instruction, or "
opcode", that most closely matches the ultimate operation can reduce the number of instructions to one, saving memory used by the program code and improving performance by leaving the
data bus open for other operations. Internally, however, these instructions are not separate operations, but sequences of the operations the units actually perform. Converting a single instruction read from memory into the sequence of internal actions is the duty of the
control unit, another unit within the processor.
Microcode The basic idea behind microcode is to replace the custom hardware logic implementing the instruction sequencing with a series of simple instructions run in a "microcode engine" in the processor. Whereas a custom logic system might have a series of diodes and gates that output a series of voltages on various control lines, the microcode engine is connected to these lines instead, and these are turned on and off as the engine reads the microcode instructions in sequence. The microcode instructions are often bit encoded to those lines, for instance, if bit 8 is true, that might mean that the ALU should be paused awaiting data. In this respect microcode is somewhat similar to the paper rolls in a
player piano, where the holes represent which key should be pressed. The distinction between custom logic and microcode may seem small, one uses a pattern of diodes and gates to decode the instruction and produce a sequence of signals, whereas the other encodes the signals as microinstructions that are read in sequence to produce the same results. The critical difference is that in a custom logic design, changes to the individual steps require the hardware to be redesigned. Using microcode, all that changes is the code stored in the memory containing the microcode or the storage device from which the microcode is loaded into the control store. This makes it much easier to fix problems in a microcode system. It also means that there is no effective limit to the complexity of the instructions, it is only limited by the amount of memory one is willing to use. The lowest layer in a computer's software stack is traditionally raw
machine code instructions for the processor. In microcoded processors, fetching and decoding those instructions, and executing them, may be done by microcode. To avoid confusion, each microprogram-related element is differentiated by the
micro prefix: microinstruction, microassembler, microprogrammer, etc. Complex digital processors may also employ more than one (possibly microcode-based)
control unit in order to delegate sub-tasks that must be performed essentially asynchronously in parallel. For example, the
VAX 9000 has a hardwired IBox unit to fetch and decode instructions, which it hands to a microcoded EBox unit to be executed, and the
VAX 8800 has both a microcoded IBox and a microcoded EBox. A high-level programmer, or even an
assembly language programmer, does not normally see or change microcode. Unlike machine code, which often retains some
backward compatibility among different processors in a family, microcode only runs on the exact
electronic circuitry for which it is designed, as it constitutes an inherent part of the particular processor design itself.
Design Engineers normally write the microcode during the design phase of a processor, storing it in a
read-only memory (ROM) or
programmable logic array (PLA) structure, or in a combination of both. However, machines also exist that have some or all microcode stored in
static random-access memory (SRAM) or
flash memory. This is traditionally denoted as
writable control store in the context of computers, which can be either read-only or
read–write memory. In the latter case, the CPU initialization process loads microcode into the control store from another storage medium, with the possibility of altering the microcode to correct bugs in the instruction set, or to implement new machine instructions.
Microprograms Microprograms consist of series of microinstructions, which control the CPU at a very fundamental level of hardware circuitry. For example, a single typical
horizontal microinstruction might specify the following operations simultaneously: • Connect register 1 to the
A side of the
ALU • Connect register 7 to the
B side of the ALU • Set the ALU to perform
two's-complement addition • Set the ALU's carry input to zero • Connect the ALU output to register 8 • Update the condition codes from the ALU status flags (
negative,
zero,
overflow, and
carry) • Microjump to a given
μPC address for the next microinstruction To simultaneously control all processor's features in one cycle, the microinstruction is often wider than 50 bits; e.g., 128 bits on a
360/85 with an emulator feature. Microprograms are carefully designed and optimized for the fastest possible execution, as a slow microprogram would result in a slow machine instruction and degraded performance for related application programs that use such instructions. ==Justification==