Microprogram Example for Add Instruction with Addressing Modes 

In this section, we will discuss the microroutine for an ADD instruction with several addressing modes. The format of the ADD instruction is shown below:

ADD Rdst, Rsrc

This instruction adds the source operand to the contents of the register Rdst and places the sum in Rdst. Assume that the source operand can be specified in one of the following addressing modes:
Register: Rsrc contains the source operand.
Autoincrement: Rsc contains the address of the source operand in memory. Rsrc will be incremented after reading the operand from memory.
Autodecrement: Rsc contains the address of the source operand in memory. Rsrc is decremented before reading the operand from memory.
Indexed: Rsc plus a displacement form the address of the source operand in memory. It is assumed that the displacement is stored in the address following the instruction address.

In addition, each of these addressing modes can be either direct or indirect. In the indirect form, an additional memory read operation is performed to obtain the required operand. For example, in the register indirect addressing mode, the register contains the address of the operand. Similarly, in the Autoincrement indirect addressing mode, Rsrc contains the address of the address of the operand. So, the content of the memory address pointed by Rsrc, is the address of the operand and not the operand. So, in this case two memory reads are needed. Thus, in total the ADD instruction has 8 addressing modes for the source operand.

The instruction is assumed to be 16-bits and its format is shown below:

Bits 15-11 Bits 10-8 Bits 7-4 Bits 3-0
Opcode Addressing mode of source Rsrc Rdst

Bit 10 and 9 indicate the four addressing modes:
00: register
01: autoincrement
10: autodecrement
11: indexed

Bit 8 indicates whether the addressing mode is direct or indirect; 0=direct, 1=indirect. It is assumed that there are 16 registers in this design so 4 bits are assigned for Rsrc and 4 bits for Rdst.

The microprogram for the ADD instruction with the 8 addressing modes is shown in the following diagram. It is assumed that both the instruction and data operands are 16 bits.

Fig. m300155.1 Microroutine Example

Multiway Branching

As can be seen from the microprogram for the ADD instruction with addressing modes, we need to branch to different addresses depending on the addressing mode. For example, for the addressing modes autoincrement, autodecrement and indexed, depending on whether the instruction is direct or indirect we need to branch to either address 170 or 171. This is called multiway branching.

Multiway branching for this case can be implemented in one of the following techniques:
Use two uBranch instructions, one is conditional based on bit 8 of the instruction register.
Include two uBranch fields within a branch microinstruction, where each field is used to generate a particular uBranch address depending on bit 8.
Bit Oring: Specify one address and use an OR gate to change the address depending on bit 8.

The most efficient way for solving multiway branching is Bit Oring. The first technique increases the size of the control store as two microinstructions will be used. The second technique also increases the size of the control store as two uBranch addresses are included in each microinstruction.

With a large number of instructions with different addressing modes, generating large number of branch addresses increases circuit complexity. A simple and inexpensive way of generating the required branch addresses is to use a Programmable Logic Array (PLA). The opcode of the machine instruction is translated into the starting address of the corresponding microroutine.

Since the source operand is fetched depending on the addressing mode, this results in the need for multiway branching depending on the addressing mode. In this case, Bit Oring can also be used as an effective solution for multiway branching.

Bit Oring

In this example, it is assumed that the addresses are in octal format, i.e. 3 bits per digit. The difference between the address for the direct addressing mode, 171, and the address for the indirect addressing mode, 170, is just bit 0. Thus, the microroutine will specify the address 170 and let the Bit Oring circuitry either keep Bit 0 as is or change it to 1. This is done based on Bit 8 that controls whether the addressing mode is direct or indirect.

The required addresses for fetching the source operand according to the addressing modes are shown below:

Addressing Mode Address
Register Direct 101
Register Indirect 111
Autoincrement 121
Autodecrement 141
Indexed 161

As can be observed, these addresses differ only in the middle digit. So, the address 101 can be stored in the microroutine and Bits 9 and 10 are used to change the middle digit in the address according to the addressing mode using Bit Oring.

The Bit Oring circuitry implementing multiway branching for this example is shown below:

Fig. m300155.2 Bit Oring Circuitry

Note that the octal address 101 is obtained from the PLA when the ADD instruction is decoded and loaded into the uPC after Oring with bits 10, 9, and 8. Bit 8 is Ored with the least significant bit going to the uPC to choose between addresses 170 and 171.

The control signal ORindrsrc is used to enable or disable Bit Oring for the case of direct and indirect addressing mode. When this signal is 0, the output of the AND gate is 0 and the address generated will be unadjusted. Similarly, the control signal ORmode is used to enable or disable Bit Oring for modifying the middle address digit. When this signal is 0, Bit Oring is disabled.

Note that the Bit Oring circuitry is placed after the 4x1 multiplexer in the design. This way, it can alter the address generated by the PLA or the uBranch address if needed.

The microroutine for the Autoincrement addressing mode for the ADD instruction using Bit Oring is shown below:

Address (Octal) Microinstruction
000 PCout, MARin, Read, ALU(C=B+2), Zin
001 Zout, PCin, WMFC
002 MDRout, IRin, uBranch{ uPC<-101 (from PLA); UPC5,4<-[IR10,9]; UPC3<-[IR10]' . [IR9]' . [IR8] }
121 Rsrcout, MARin, Read, ALU(C=B+2), Zin
122 Zout, Rsrcin, WMFC, uBranch{ uPC<-170 (from uBranch field); UPC0<-[IR8]' }
170 MDRout, MARin, Read, WMFC
171 MDRout, Yin
172 Rdstout, ALU(C=A+B), Zin
173 Zout, Rdstin, End

To accommodate Bit Oring for this example, two bits are added in the uBranch control signals for controlling the signals ORindrsrc and ORmode. The control store content for this example is shown below:

Address MS1 MS0 BrUn BrNotZ BrZ BrNotN BrN ORindrsrc ORmode Control signals Branch Address
000 00 0 0 0 0 0 0 0 ... xxx
001 00 0 0 0 0 0 0 0 ... xxx
002 01 0 0 0 0 0 0 1 ... xxx
121 00 0 0 0 0 0 0 0 ... xxx
122 11 1 0 0 0 0 1 0 ... 170
170 00 0 0 0 0 0 0 0 ... xxx
171 00 0 0 0 0 0 0 0 ... xxx
172 00 0 0 0 0 0 0 0 ... xxx
173 11 1 0 0 0 0 0 0 ... 000

Note that the microroutine is not terminated by the END signal. Instead, the starting address of the fetch microroutine is specified in the uBranch address field.