
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Horizontal vs. Vertical Micro–Code The micro–programming strategy called “ horizontal microcode ” allows one bit in the micro–memory for each control signal generated. We have illustrated this with a small memory to issue control signals for bus B1. There are five control signals associated with this bus, so this part of the micro–memory would comprise five–bit numbers. A quick count from the table of control signals shows that there are thirty–four discrete control signals associated with this control unit. A full horizontal implementation of the microcode would thus require 34 bits in each micro–word just to issue the control signals. The memory width is not a big issue; indeed there are commercial computers with much wider micro–memories. We just note the width requirement. In vertical microcoding , each signal is assigned a numeric code that is unique for its function. Thus, each of the five signals for control of bus B1 would be assigned a numeric code. The following table illustrates the codes actually used in the design of the Boz–5. Code Signal 000 001 PC B 010 MAR B 011 R B 100 IR B 101 SP B It is particularly important that a vertical microcoding scheme allow for the option that no signal is being placed on the bus. In this design we reserve the code 0 for “nothing on bus” or “ALU does nothing”, etc. The three bits in this design are placed into a 3–to–8 decoder, as shown in the figure below. Admittedly, this design is slower than the horizontal microcode in that it incurs the time penalty associated with the decoder. Figure: Sample of Vertical Microcoding In this revised example, word 105 generates MAR B1 and word 106 generates R B1.
One advantage of encoding the control signals is the unique definition of the signal for each function. As an example, consider both the horizontal and vertical encodings for bus B1. In the five–bit horizontal encoding, we were required to have at most one 1 per micro–word. An examination of that figure will show that the micro–word “10100” would assert the two control signals PC B1 and R B1 simultaneously, causing considerable difficulties. In the vertical microcoding example, the three–bit micro–word with contents “011” causes the control signal R B1, and only that control signal, to be asserted. To be repetitive, the code “000” is reserved for not specifying any source for bus B1; in which case the contents of the bus are not specified. In such a case, the ALU cannot accept input from bus B1. The design chosen for the microcode will be based on the fact that four of the CPU units (bus B1, bus B2, bus B3, and the ALU) can each have only one “function”. For this reason, the control signals for these units will be encoded. There are seven additional control signals that could be asserted in any combination. These signals will be represented in horizontal microcode, with one bit for each signal. Structure of the Boz–5 Microcode As indicated above, the Boz–5 microcode will be a mix of horizontal and vertical microcode. The reader will note that some of the encoded fields require 3–bit codes and some require 4–bit codes. For uniformity of notation we shall require that each field be encoded in 4 bits. The requirement that each field be encoded by a 4–bit binary number has no justification in engineering practice. Rather it is a convenience to the student, designed to remove at least one minor nuisance from the tedium of writing binary microcode and converting it to hex. Consider the following example, taken from the common fetch sequence. MBR B2, tra2, B3 IR. A minimal–width encoding of this sequence of control signals would yield the following. 0 000 110 100 010 000 0000 0000 0000 0000 0000. Conversion of this to hexadecimal requires regrouping the bits and then rewriting. 0000 1101 0001 0000 0000 0000 0000 0000 0000 or 0x0 D100 0000 The four–bit constant width coding of this sequence yields the following. 0000 0000 0110 0100 0010 0000 0000 0000 0000 0000 0000 This is immediately converted to 0x006 4200 0000 without shuffling any bits. Dispatching the Microcode In addition to micro–words that cause control signals to be emitted, we need micro–words to sequence the execution of the microcode. This is seen most obviously in the requirement for a dispatch based on the assembly language op–code. Let’s begin with an observation that is immediately obvious. If the microprogrammed control unit is to handle each distinct assembly language opcode differently, it must have sections of microprogram that are unique to each of the assembly language instructions. The solution to this will be a dispatch microoperation , one which invokes a section of the microprogram that is selected based on the 5–bit opcode that is currently in the Instruction Register. But what is called and how does it return?
While the above sequence corresponds to a coding model that would be perfectly acceptable at the assembly language level, it presents several significant problems at the microcode level. We begin with the observation that it requires the introduction of an explicitly managed microprogram counter in addition to the micro–memory address register. The second, and most significant, drawback to the above design is that it requires two clock pulses to execute what the hardwired control unit executed in one clock pulse. One might also note that the present design calls for using two micro–words (addresses 0x80 and 0x81) where one micro–word might do. This is a valid observation, but the cost of memory is far less significant than the “time cost” to execute the extra instruction. The design choice taken here is to encode the address of the next microinstruction in each microinstruction in the microprogram. This removes the complexity of managing a program counter and the necessity of the time–consuming explicit branch instruction. Recasting the example above in the context of our latest decision leads to the following sequence. Address Control Signals Next address 0x20 PC B1, tra1 , B3 MAR, READ. 0x 0x21 PC B1, 1 B2, add , B3 PC. 0x 0x22 MBR B2, tra2 , B3 IR. 0x 0x23 Dispatch based on IR 31 –IR 27. ?? – We decide later 0x80 R B1, R B2, and , B3 R. 0x Note that the introduction of an explicit next address causes the execution phase of the logical AND instruction to be reduced to one clock pulse, as desired. The requirement for uniformity of microcode words leads to use of an explicit next address in every micro–word in the micromemory. The only microinstruction that appears not to require an explicit next address in the dispatch found at address 0x23. A possible use for the next address field of the dispatch instruction is seen when we consider the effort put into the hardwired control unit to avoid wasting execution time on a Branch instruction when the branch condition was not met. The implementation of this decision in a microprogrammed control unit is to elect not to dispatch to the opcode–specific microcode when the instruction is a branch and the condition is not met. What we have is shown below. Address Control Signals Next address 0x20 PC B1, tra1 , B3 MAR, READ. 0x 0x21 PC B1, 1 B2, add , B3 PC. 0x 0x22 MBR B2, tra2 , B3 IR. 0x 0x23 Dispatch based on IR 31 –IR 27. 0x 0x80 R B1, R B2, and , B3 R. 0x The present design places the next address for dispatch when the condition is not met in the field of the micro–word associated with the next address for two reasons:
At this point in the design of the microprogrammed control unit, we have two distinct types of microoperations: a type that issues control signals and a type that dispatches based on the assembly language opcode. To handle this distinction, we introduce the idea of a micro– opcode with the following values at present. Micro–Op Function 0000 Issue control signals 0001 Dispatch based on the assembly language opcode. We have stated that there are conditions under which the dispatch will not be taken. There is only one condition that will not be dispatched: the assembly–language opcode is 0x0F and the branch condition is not met. Before we consider how to handle this situation, we must first address another design issue, that presented by indirect addressing. Handling Defer Consider the control signals for the LDR (Load Register) assembly language instruction. LDR Op-Code = 01100 (Hexadecimal 0x0C) F, T0: PC B1, tra1 , B3 MAR, READ. // MAR (PC) F, T1: PC B1, 1 B2, add , B3 PC. // PC (PC) + 1 F, T2: MBR B2, tra2 , B3 IR. // IR (MBR) F, T3: IR B1, R B2, add , B3 MAR. // Do the indexing. Here the major state register takes control.
This leads to a simple statement defining this sequencing signal. S1 = 0 if and only if the assembly language opcode = 0x0F and branch = 0, where branch = 1 if and only if the branch condition is met. The sequencing signal S2 is used to control the entering of the defer code for those instructions that can use indirect addressing. Recall that the assignment of opcodes to the assembly language instructions has been structured so that only instructions beginning with “011” can enter the defer phase. Even these enter the defer phase only when IR 26 = 1. Thus, we have the following definition of this signal. S2 = 1 if and only if (IR 31 = 0, IR 30 = 1, IR 29 = 1, and IR 26 = 1) In a way, this is exactly the definition of the sequencing control signal S 2 as used in the hardwired control unit. The only difference is that in this design the signal S2 must be used independently of the signal S1, so we must use the full definition. The figure below illustrates the circuitry to generate the two sequencing signals S1 and S2. Given these circuits, we have the final form and labeling of the micro–words in the micro– memory. Note that there are no “micro–data” words, only microinstructions. Micro–Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 4 bit 4 bit 4 bit 4 bit 4 bit 4 bit 4 bit 8 bit 8 bit The form of the type 1 instruction is completely defined and can be given as follows. Micro–Op B1 B2 B3 ALU M1 M2 D = 0 D = 1 0001 0x0 0x0 0x0 0x0 0x0 0x0 0x20 0x But what exactly does this dispatch instruction do? The question becomes one of defining the dispatch table, which is used to determine the address of the microcode that is invoked explicitly by this dispatch. We now address that issue.
The design of the Boz–5 uses a dispatch mechanism copied from that used by Andrew S. Tanenbaum in his textbook Structured Computer Organization (Fifth Edition, published by Pearson/Prentice–Hall in 2006; ISBN 0 – 13 – 148521 – 0). It is apparent that this dispatch mechanism is commonly used in many commercial implementations of microcode. The solution is to use the opcode itself as the dispatch address. As the Boz–5 uses a five bit opcode, the sequencer unit for the microprogrammed control unit must expand it to an 8–bit address by adding three high order 0 bits so that the dispatch address is 000 ¢ IR31–27. As an example, the binary opcode for LDR is 01100; its dispatch address is 0000 1100 or 0x0C. The Boz–5 uses five–bit opcodes, with range 0x00 through 0x1F. It then follows that addresses 0x00 through 0x1F in the micromemory must be reserved for dispatch addresses. It is for this reason that the common fetch sequence begins at address 0x20; that is the next available address. We now see that this structure works only because the address of the next microinstruction is explicitly encoded in the microinstruction. This dispatch mechanism works very well on the 14 of 22 assembly language instructions that complete execution in one additional clock pulse. As examples, we examine the control signals for the first 8 opcodes (0x00 – 0x07) along with the common fetch microcode. Address Micro Control Signals Next Address Opcode S2 = 0 S2 = 1 0x00 0 0 RUN 0x20 0x 0x01 0 IR B1, extend , tra1 , B3 R 0x20 0x 0x02 0 IR B1, R B2, and , B3 R 0x20 0x 0x03 0 IR B1, R B2, extend , add , B3 R 0x20 0x 0x04 0 NOP 0x20 0x 0x05 0 NOP 0x20 0x 0x06 0 NOP 0x20 0x 0x07 0 NOP 0x20 0x 0x20 0 PC B1, tra1 , B3 MAR, READ 0x21 0x 0x21 0 PC B1, 1 B2, add , B3 PC 0x22 0x 0x22 0 MBR B2, tra2 , B3 IR 0x23 0x 0x23 1 Dispatch based on opcode 0x20 0x At this point, our design continues to look sound. Note that the unused opcodes (those at microprogram addresses 0x04 through 0x07) simply do nothing and return to the common fetch sequence at address 0x20. This allows for future expansion of the instruction set. The only problem left to be addressed is the proper handling of instructions that require more than one clock cycle (following the common fetch) in which to execute. The first such instruction is the GET assembly language instruction.
Assignment of Numeric Codes to Control Signals We now start writing the microcode. This step begins with the assignment of numeric values to the control signals that the control unit emits. The next table shows the numeric codes that this author has elected to assign to the encoded control signals; these being the controls for bus B1, bus B2, bus B3, and the ALU. While the assignment may appear almost random, it does have some logic. The basic rule is that code 0 does nothing. The bus codes have been adjusted to have the greatest commonality; thus code 6 is the code for both MBR B2 and B3 MBR. Code Bus 1 Bus 2 Bus 3 ALU 0 1 PC B1 1 B2 B3 PC tra 2 MAR B1 – 1 B2 B3 MAR tra 3 R B1 R B2 B3 R shift 4 IR B1 B3 IR not 5 SP B1 B3 SP add 6 MBR B2 B3 MBR sub 7 IOD B2 B3 IOD and 8 B3 IOA or 9 xor 10 Other assignments may be legitimately defended, but this is the one we use. Example: Common Fetch Sequence We begin our discussion of microprogramming by listing the control signals for the first three minor cycles in the Fetch major cycle and translating these to microcode. We shall mention here, and frequently, that the major and minor cycles are present in the microcode only implicitly. It is better to think that major cycles map into sections of microcode. For this example, we do the work explicitly. Location 0x20 F, T0: PC B1 B1 code is 1 tra1 ALU code is 1 B3 MAR B3 code is 2 READ M2(Bit 3) = 1, so M2 = 8 Micro–Op = 0. B2 code and M1 code are both 0. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x20 0 1 0 2 1 0 8 0x21 0x
Location 0x21 F, T1: PC B1 B1 code is 1 1 B2 B2 code is 1 add ALU code is 5 B3 PC. B3 code is 1 Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x21 0 1 1 1 5 0 0 0x22 0x Location 0x22 F, T2: MBR B2 B2 code is 6 tra2 ALU code is 2 B3 IR B3 code is 4 Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x22 0 0 6 4 2 0 0 0x23 0x Location 0x23 Dispatch on the op–code in the machine language instruction For this we assume that the Micro–Op is 1 and that none of the other fields are used. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x23 1 0 0 0 0 0 0 0x20 0x Here is the microprogram for the common fetch sequence. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x20 0 1 0 2 1 0 8 0x21 0x 0x21 0 1 1 1 5 0 0 0x22 0x 0x22 0 0 6 4 2 0 0 0x23 0x 0x23 1 0 0 0 0 0 0 0x20 0x Here is the section of microprogram for the common fetch sequence, written in the form that would be seen in a utility used for debugging the microcode. Address Contents 0x20 0x010 2108 2121 0x21 0x011 1500 2222 0x22 0x006 4200 2323 0x23 0x100 0000 2020 We now have assembled all of the design tricks required to write microcode and have examined some microcode in detail. It is time to finish the microprogramming.
For the moment, let’s skip the next eight opcodes and finish the simpler cases. LLS Op-Code = 10000 R B2, shift , L /R = 1, A = 0. C = 0, B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x10 0 0 3 3 3 8 0 0x20 0x LCS Op-Code = 10001 R B2, shift , L /R = 1, A = 0. C = 1, B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x11 0 0 3 3 3 9 0 0x20 0x RLS Op-Code = 10010 R B2, shift , L /R = 0, A = 0. C = 0, B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x12 0 0 3 3 3 0 0 0x20 0x RAS Op-Code = 10011 R B2, shift , L /R = 0, A = 1. C = 0, B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x13 0 0 3 3 3 4 0 0x20 0x NOT Op-Code = 10100 R B2, not, B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x14 0 0 3 3 4 0 0 0x20 0x ADD Op-Code = 10101 R B1, R B2, add , B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x15 0 3 3 3 5 0 0 0x20 0x SUB Op-Code = 10110 R B1, R B2, sub , B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x16 0 3 3 3 6 0 0 0x20 0x AND Op-Code = 10111 R B1, R B2, and , B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x17 0 3 3 3 7 0 0 0x20 0x OR Op-Code = 11000 R B1, R B2, or , B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x18 0 3 3 3 8 0 0 0x20 0x XOR Op-Code = 11001 R B1, R B2, xor , B3 R. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x19 0 3 3 3 9 0 0 0x20 0x We have now completed the microprogramming for all but eight of the instructions. The table on the next page shows what we have generated up to this point.
0x0B 0x0C 0x0D 0x0E Note that instructions 0x1A through 0x1F are not yet implemented, so they show as NOP’s. We now move to those instructions that require Defer and Execute for completion. Due to
SP B1, – 1 B2, add, B3 SP Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x0A 0 5 2 5 5 0 0 0x26 0x SP B1, tra1, B3 MAR, READ. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x26 0 5 0 2 1 0 8 0x27 0x WAIT Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x27 0 0 0 0 0 0 0 0x28 0x MBR B2, tra2 , B3 PC Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x28 0 0 6 1 2 0 0 0x20 0x RTI Op-Code = 01011 (Hexadecimal 0x0B) Not yet implemented. This is encoded as another NOP, until time to develop the details of interrupt handling. The “link” Address Micro-Op B1 B2 B3 ALU M1 M2 B = 0 B = 1 0x0B 0 0 0 0 0 0 0 0x20 0x We now turn to the four instructions that use both Defer and Execute. One might be tempted to write a common Defer “subroutine” to be “called” by each of the Execute sections. While this would reduce duplication of micro–code, we opt for in–line coding. In each of the following four instructions, the step corresponding to (F, T3) issues control signals. These will be issued by the “link” micro–operation. We must also introduce a new micro–op to account for conditionally entering or not entering the Defer section.
The next four assembly language instructions (LDR, STR, JSR, and BR) are the only that possibly use indirect addressing. As discussed in our presentation of the sequencing control signals for the microprogram, the defer phase will be entered if and only if S2 = 1. The template for the DEFER state is shown below. It has one essential WAIT state. X READ X + 1 WAIT X + 2 MBR B2, tra2 , B3 MAR X + 3 Code for E, T Due to this structure, the address for (S2 = = 0) will be 3 more than that for (S2 = = 1). LDR Op-Code = 01100 (Hexadecimal 0x0C) F, T3: IR B1, R B2, add , B3 MAR. // Do the indexing. D, T0: READ. // Address is already in the MAR. D, T1: WAIT. // Cannot access the MBR just now. D, T2: MBR B2, tra2 , B3 MAR. // MAR (MBR) D, T3: WAIT. E, T0: READ. // Again, address is already in the MAR. E, T1: WAIT. E, T2; MBR B2, tra2 , B3 R. E, T3: WAIT. IR B1, R B2, add , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x0C 0 4 3 2 5 0 0 0x2C 0x READ Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x29 0 0 0 0 0 0 8 0x2A 0x2A WAIT Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x2A 0 0 0 0 0 0 0 0x2B 0x2B MBR B2, tra2 , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x2B 0 0 6 2 2 0 0 0x2C 0x2C READ. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x2C 0 0 0 0 0 0 8 0x2D 0x2D WAIT. Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x2D 0 0 0 0 0 0 0 0x2E 0x2E MBR B2, tra2 , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x2E 0 0 6 2 2 0 0 0x20 0x
JSR Op-Code = 01110 (Hexadecimal 0x0E) F, T3: IR B1, R B2, add , B3 MAR. // Do the indexing. D, T0: READ. // Address is already in the MAR. D, T1: WAIT. // Cannot access the MBR just now. D, T2: MBR B2, tra2, B3 MAR. // MAR (MBR) D, T3: WAIT. E, T0: PC B1, tra1 , B3 MBR. // Put return address in MBR E, T1: MAR B1, tra1 , B3 PC. // Set up for jump to target. E, T2: SP B1, tra1 , B3 MAR, WRITE. // Put return address on stack. E, T3: SP B1, 1 B2, add , B3 SP. // Bump SP IR B1, R B2, add , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x0E 0 4 3 2 5 0 0 0x37 0x READ Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x34 0 0 0 0 0 0 8 0x35 0x WAIT Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x35 0 0 0 0 0 0 0 0x36 0x MBR B2, tra2 , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x36 0 0 6 2 2 0 0 0x37 0x PC B1, tra1 , B3 MBR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x37 0 1 0 6 1 0 0 0x38 0x MAR B1, tra1 , B3 PC Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x38 0 2 0 1 1 0 0 0x39 0x SP B1, tra1 , B3 MAR, WRITE Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x39 0 5 0 2 1 0 0 0x3A 0x3A SP B1, 1 B2, add , B3 SP Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x3A 0 5 1 5 5 0 0 0x20 0x
BR Op-Code = 01111 (Hexadecimal 0x0F) F, T3: IR B1, R B2, add , B3 MAR. // Do the indexing. D, T0: READ. // Address is already in the MAR. D, T1: WAIT. // Cannot access the MBR just now. D, T2: MBR B2, tra2, B3 MAR. // MAR (MBR) D, T3: WAIT. E, T0: WAIT. E, T1: WAIT. E, T2: WAIT. E, T3: MAR B1, tra1 , B3 PC. Remember that the microcode at address 0x23 will not dispatch to address 0x0F if the branch condition is not true. This avoids wasted time and incorrect execution. IR B1, R B2, add , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x0F 0 4 3 2 5 0 0 0x3E 0x3B READ Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x3B 0 0 0 0 0 0 8 0x3C 0x3C WAIT Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x3C 0 0 0 0 0 0 0 0x3D 0x3D MBR B2, tra2 , B3 MAR Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x3D 0 0 6 2 2 0 0 0x3E 0x3E MAR B1, tra1 , B3 PC Address Micro-Op B1 B2 B3 ALU M1 M2 S2 = 0 S2 = 1 0x3E 0 2 0 1 1 0 0 0x20 0x This completes the derivation of the microprogram for the Boz–5.