Microprogramming Details

This page is meant to supplement the section in the course notes on microprogramming. It gives some extra details on the microinstruction fields, as well as exactly how memory accesses work. Please send any comments/questions to the tutor (cs251@student.cs.uwaterloo.ca).

Microinstruction Fields

Label

This is essentially the name of the line of microcode. You can choose anything you'd like. The label is useful for branching and jumping. For example, if you had a line called line7, you would use that name anytime you wanted to branch or jump to that line.

ALU Ctrl

This specifies the operation the ALU should do. The choices are add, subtract, and func. The func operation is something you would rarely use. It is primarily there for the implementation of R-format instructions, where the ALU would use the function bits within that instruction to determine which operation to use.

SRC1 and SRC2

These refer to the sources of the two multiplexors that choose the inputs to the ALU. The ALU computation will use SRC1 and SRC2 as its operands. Please refer to the microprogrammed datapath as you read the following explanations.

The multiplexor for SRC1 has two choices:

The multiplexor for SRC2 has four choices:

Reg RW

This column is perhaps the most difficult to interpret. It contains two components; the read component, and the write component. Both are optional.

The read component has the following format:

R <read_register_1> <read_register_2>

Note that the datapath does not allow for rt to be read register 1 or rs to be read register 2. Also, rd cannot be a read register (only a write register).

Whatever data is contained in read register 1 will be outputted onto line A, and whatever data is contained in read register 2 will be outputted onto line B.

The write component has the following format:

W <source> <destination>

The destination will be a register; either $32-$63, rd, or rt. Note that the datapath does not make it possible to write to rs. Writing to registers less than 32 can be done, but 99% of the time you won't want to do this since you might be overwriting something important.

There are 2 options for the source: ALU or Mem. ALU simply takes the result of the ALU computation, and puts it into the destination register. Mem will take the data in memory at a precomputed address (more on this later), and put it into the destination register.

Mem

This column specifies what should happen to memory during the current clock cycle. There are three choices:

Please see the Memory Access section further below for a more complete explanation of how to read and write from memory.

PCWrite

This column indicates any changes that may take place in the program counter. More specifically, it controls the PCSource multiplexor. The table in the course notes as well as the datapath should sufficiently explain the possibilities for this column.

Sequencing

This column determines which instruction your microprogram should execute next. Be careful not to confuse this with changes to the program counter, which specifies what instruction the MIPS program should execute next. This column has several choices:

Constant

The constant has several potential uses. See the SRC1 and SRC2 and Sequencing subsections for details.

Memory Access

Microprogramming a memory access can be a little difficult. It needs two clock cycles to be accomplished. In the first clock cycle, the address to be read from or written to is computed. In the second clock cycle, the memory is actually read or written.

The trick here is to make use of the ALUAddr register. The result of every ALU computation that takes place is stored in this register for the next clock cycle. To do a memory access then, you do the following:

Also see the lw and sw microprogramming examples in the course notes.