Microcode: Difference between revisions

Content deleted Content added
Many changes to improve technical and historical accuracy
Line 1:
A '''microprogram''' implements a [[CPU]] [[instruction set]]. Just as a single [[high level language]] statement is [[compiled]] to a series of [[machine instruction]]s (load, store, shift, etc), each machine instruction is in turn implemented by a series of microinstructions, sometimes called a microprogram. The most common term is microcode, not microprogram.
A '''microprogram''' is a highly-specialized [[computer program]] that allows one computer microarchitecture to [[Emulator|emulate]] another, usually more-complex architecture. The '''microcode''' of a microprogram is usually very small compared to ordinary software, hence its name. It is also very carefully designed and optimized for the fastest possible execution.
 
On most computers the microcode is not produced by a compiler, but exists in a special high speed memory. The microcode is written by the CPU engineer during the design phase. In some computers the microcode is in [[RAM]] and can be altered to correct bugs in the instruction set, or to implement new machine instructions. Microcode can also allow one computer [[microarchitecture]] to [[Emulator|emulate]] another, usually more-complex architecture.
 
The elements composing the microprogram exist on a lower conceptual level than the more familiar assembler instructions. Each element is differentiated by the "micro" prefix to avoid confusion: microprogram, microcode, microinstruction, microassembler, etc.
 
Microprograms are carefully designed and optimized for the fastest possible execution, since a slow microprogram would yield a slow machine instruction which would in turn cause all programs using that to be slow. The microprogrammer must have extensive low-level hardware knowledge of the computer circuitry, as the microcode controls this.
 
The [[computer storage|memory]] in which the [[Central processing unit|CPU's]] ''microcode'' resides is called a [[control store]]. The microcode may be stored in ROM (as a form of [[firmware]]) or loaded into [[RAM]] memory as part of the initialization of the central processing unit.
 
As with any computer program, microprogramsMicroprograms consist of series of microinstructions. These microinstructions usually control the computer's [[central processing unit]] ([[Central processing unit|CPU]]) at a very fundamental level. For example, a single typical microinstruction might specify the following operations:
 
* Connect Register 1 to the "A" side of the [[ALU]]
Line 16 ⟶ 22:
 
== The reason for microprogramming ==
MicroprogrammingMicrocode was originally developed as a simpler method of developing the control logic for a computer. AsInitially logicCPU designinstruction techniquessets improvedwere "hard wired". Each machine instruction (add, thisshift, reasonmove) declinedwas inimplemented importancedirectly with circuitry. This provided fast performance, but otheras instruction sets grew more complex, hard-wired instruction reasonssets became more importantdifficult to design and debug.
 
Microcode alleviated that problem by allowing CPU design engineers to write a microprogram to implement a machine instruction rather than design circuitry for that. Even late in the design process, microcode could easily be changed, whereas hard wired instructions could not. This greatly facilitated CPU design and led to more complex instruction sets.
 
When computers were first developed, the speed of the central processor approximately matched the speed of the main memory, and each instruction word read from memory could efficiently command the execution of a single operation by the central processing unit. As logic design became more advanced, however, it became possible for the central processor to execute operations much faster than instruction words could be fetched from memory.
 
Another advantage of microcode was the implementation of more complex machine instructions. In the 1960s through the late 1970s, much programming was done in assembly language, a symbolic equivalent of machine instructions. The more abstract and higher level the machine instruction, the greater the programmer productivity. The ultimate extension of this were "Directly Executable High Level Language" designs. In these each statement of a high level language such as PL/1 would be entirely and directly executed by microcode, without compilation. The [[IBM Future Systems project]] and Data General Fountainhead Processor were examples of this. Those systems were never produced, but elements of the IBM project were implemented in the System/38 and AS/400, which used extensive microprogramming to implement high level constructs. For example the System/38 and AS/400 could perform a [[Join (SQL)| relational SQL join]] in a machine instruction.
Microprogramming was a response to this imbalance. By allowing each instruction fetched from memory to invoke a micro[[subroutine]], instructions fetched from memory could command the central processor to perform very complex operations such as the addition of floating-point numbers or the execution of complete operations on character strings. The rise of [[CISC]] computers was a direct result of the availability of microprogramming and many computer architectures such as the [[IBM]] [[System/360]] and the [[Digital Equipment Corporation|DEC]] [[VAX]] family used complex microprograms.
 
Microprogramming also helped alleviate the memory bandwidth problem. During the 1970s, CPU speeds grew more quickly than memory speeds. Numerous acceleration techniques such as memory block transfer, memory pre-fetch and multi-level caches helped reduce this. However high level machine instructions (made possible by microcode) helped further. Fewer more complex machine instructions require less memory bandwidth. For example complete operations on character strings could be done as a single machine instruction, thus avoiding multiple instruction fetches.
 
Architectures using this approach included the [[IBM]] [[System/360]] and [[Digital Equipment Corporation|DEC]] [[VAX]] family used complex microprograms. The IBM System/38 and AS/400 too this concept even further. The approach of using increasingly complex microcode-implemented instruction sets was later called [[CISC]].
In recent times, advances in memory speeds, especially [[cache memory]], have made microprogramming less necessary, leading to the return of direct-execution computer architectures. Note that [[RISC]] is not the same as direct execution, though the techniques often are found together.
 
== Other benefits ==