MicroProgramming Programming at a different level Copyright © 2005 – Curt Hill The Control Unit • What does it do? • Decodes the instruction • Causes the ALU to perform the needed actions • This can be done in two ways: – Hardwire the CU from gates – Microprogram the CU Copyright © 2005 – Curt Hill History 1 • Control Units were traditionally hardwired • Wilkes proposed in papers in 1951 and 1953 the concept of a microprogram • This is the same Wilkes of the EDSAC • It was kicked around for a while with no practical implementations Copyright © 2005 – Curt Hill History 2 • In the 1950s virtually every machine had its own machine language • Average lifetime of a machine was two years • Every two years every piece of software had to be rewritten for the new machine • This was good motivation for both microprogramming and high level languages Copyright © 2005 – Curt Hill History 3 • In the February 1964 issue of Datamation was an article decrying the commercial failure of microprogramming • In April of the same year IBM introduced the System 360 • All the low end machines were microprogrammed • The high end machines were hardwired for performance Copyright © 2005 – Curt Hill Hardwired vs. Software • A variety of applications can use either a hard or soft solution – Controllers being typical • The hard solution is a digital gate network – Such as a Programmable Logic Array • The soft solution is a microprocessor with control program • What are the tradeoffs? Copyright © 2005 – Curt Hill Tradeoffs • Given the same level of technology the hardwired solution is: – Faster – Uses fewer gates • The software solution is: – More flexible – Less error prone – Easier to maintain • The Control Unit can be either Copyright © 2005 – Curt Hill The Control Unit • May be hardwired with just a gate network • It may be microprogrammed as well • Then known as a microcontroller – Aka microprocesser, but that term is ambiguous • The software is then the microcode • Microcode comes in two formats: – Horizontal and vertical Copyright © 2005 – Curt Hill Microcode • The goal of the microcode is to sequence the ALU and other parts of CPU to implement the instruction set of the computer • In this context the instruction set of the processor is called the macrocode • Generally the microcode is not visible to the macrocode programmer • The microcode only deals with very low level features Copyright © 2005 – Curt Hill Vertical Microcode • Vertical microcode is somewhat similar to macrocode • Each macrocode instruction becomes a parameterless subroutine call • The subroutine then implements the macrocode instruction • Consider the example of a 32 bit add from System 360 Copyright © 2005 – Curt Hill Add Example • Consider the following add instruction A r4,120(r6) • It means this: – – – – Add 120 to contents of register 6 Use that address to fetch a 32 bit item Add that to contents of register 4 Leave the result in register 4 Copyright © 2005 – Curt Hill CPU Units ALU ALU Result Memory Operand A ALU Cmd Operand B Mem Cmd Register File Copyright © 2005 – Curt Hill Control Unit Vertical Microcode Implementation • Copy register 6 to ALU A • Copy last 10 bits of instruction to ALU B • Execute ALU add • Send result to memory as a fetch • Send returned memory value to ALU A • Send register 4 to ALU B • Execute ALU add • Send result to register 4 Copyright © 2005 – Curt Hill Partial Implementation • The above did nothing about several important activities of the CPU – Fetching the current instruction – Determining the length of current instruction – Incrementing Program Counter – Setting condition codes • These may be part of the microcode program or hardwired – A control unit may have a mix of hardwired and software implementation Copyright © 2005 – Curt Hill Problems • Vertical microcode must do several things for even a simple instruction such as add • Thus it must be very fast compared to the basic hardware of the CPU • It tends also to sequence the sub-parts of the instruction • This impairs performance since it does not do well with parallel execution Copyright © 2005 – Curt Hill Vertical Microcode Example • The LSI 11 used a vertical microcode instruction • Used a 22 bit micro instruction • 11 bit micro address allowing 2048 words of micro instructions • Somewhat similar to the PDP 11 instruction set that it emulated • Supplied arithmetic, logical, general and I/O operations Copyright © 2005 – Curt Hill Microcode Types • Vertical microcode looks like traditional assembly language • The exception is the items that it deals with are not always visible to the assembly language programmer • Thus it is easy for programmers to deal with • Horizontal microcode is a word where each set of bits has a particular meaning to the sub-units Copyright © 2005 – Curt Hill Horizontal Microcode • Each instruction is a word divided into fields • Each field is the command for one of the units • Using our example diagram our fields could be: – ALU • Command • Two Operands • One result – Memory – Registers Copyright © 2005 – Curt Hill CPU Units ALU ALU Result Memory Operand A ALU Cmd Operand B Mem Cmd Register File Copyright © 2005 – Curt Hill Control Unit ALU Operations • Suppose our ALU has following commands: – – – – – – – – Add Not And Or Shift left Shift right No operation Continue • Eight instructions – 3 bits of command Copyright © 2005 – Curt Hill Operands • The ALU has three registers • Two operand registers and one result register • There is an implied command for each • For the two operand registers it is: – Accept contents – Do nothing • For result it is: – Output (to lines) result – Do nothing Copyright © 2005 – Curt Hill Memory and Registers • The registers and memory have three commands: – Fetch data – Store data – Do nothing • In addition they both need an address to get or fetch from – Registers is typically 2-8 bits • May be from microcode or instruction – Memory is typically 32 or more bits • Almost always computed Copyright © 2005 – Curt Hill Horizontal Microcode 0-2 ALU command 3 Operand A command 4 Operand B command 5 Result command 6-7 Memory command 8-9 Register command Copyright © 2005 – Curt Hill Microcode Word • The above shows a 10 bit word • Memory addresses are handled in other • The microcode may have some bits to handle choosing a register • These words are dropped on the bus periodically • Hence two commands may execute at the same time – Storing a register value in memory could be simultaneously done with an ALU computation – The ALU continue command allows the ALU to take more than one cycle to finish its computation Copyright © 2005 – Curt Hill Horizontal Microcode • A different paradigm than programmers expect – Makes it more difficult to program • The parallelism makes for faster execution Copyright © 2005 – Curt Hill Example • This time use horizontal micro code – 10 opcode bits • Consider the following add instruction A r4,120(r6) • It means this: – – – – Add 120 to contents of register 6 Use that address to fetch a 32 bit item Add that to contents of register 4 Leave the result in register 4 Copyright © 2005 – Curt Hill Horizontal Microcode • 000 1 0 0 00 01 – Copy register 6 to ALU A • 000 0 1 0 00 01 – Copy last 10 bits of instruction to ALU B • 001 0 0 0 00 00 – Execute ALU add • 000 0 0 1 10 00 – Send result to memory as a fetch • This ignores: – How registers are selected – How pieces of instruction are used – All parallelism Copyright © 2005 – Curt Hill IBM 360 Example • Microprogramming was used to make all the machines to have the same macroinstruction set • The model 20 was a 16 bit machine • The model 30, 40, 50, 60 were microprogrammed 32 bit machine • These came out before semiconductor ROM – Used IMPL to start • The model 90 was a high end scientific machine Copyright © 2005 – Curt Hill IBM 3033 Example • • • • Successor to 360/370 Horizontal microcode 4096 word control store Two sizes of micro instructions – 2048 108 bit micro instructions – 2048 126 bit micro instructions Copyright © 2005 – Curt Hill Partial Microprogramming • The instruction set of a computer could be mostly set • That is the microcode is in ROM • However, allow undefined opcodes to be programmed as microcode subroutines in some type of PROM • IBM used unused opcodes in the 370 and 3000 series to speed the OS and other products – Common code made an instruction Copyright © 2005 – Curt Hill The Day Has Passed • The heyday of microprogramming was the 60-70s • It simplified CU design and made it easy • Then CPUs were constructed out of discrete chips • The age of one chip microprocessors ended the day • Now a single CPU chip can generally run software faster than the many chips with custom microprogram Copyright © 2005 – Curt Hill Last Thoughts • There is no reason why the microprogram could not be a ROM external to the main chip • However, in most cases it is not needed • Only specialized CPUs such as runs the Java Byte Code would need • The price of software is too large for most new machine designs Copyright © 2005 – Curt Hill