CS355 Sylabus

# Intro to Micro Programming

• First and foremost: we build the CPU and its datapath for a specific purpose: to execute (assembler coded) instructions fetched from memory.

The CPU execute assembler instructions in the following manner:

• Fetch the assembler instruction from memory at location given by the PC (program counter) register
• Update PC and make it point to the next assembler instruction
• Decode (find out what the instruction does)
• Fetch operands
• Perform the operation
• Write result to the destination

The CPU perform these steps over and over and over again.... These steps are called the "instruction execution cycle".

Here is the CS255 material on the instruction execution cycle in case you forgot: click here

• You can now smell what will happen next:

• We will write a sequence of micro-instructions that instructs the datapath to perform the steps of the instruction execution cycles over and over again... until hell freezes over or until you unplug the computer... :-)

• The micro-program will look something like this:

```     Address            Micro instruction at this address
=======            ==================================
0               00000000110000000000000000000000
1               00000001010100000110000000000000
2                ... and so on ...
```

Needless to say that I will drive many students crazy if I am gonna explain this micro-program in "bit" form to you.

And yet, I have to present the micro-program to you to complete your understanding of the computer.

Fortunately, you knows assembler programming from CS255 and in CS255, you have learned to use mnemonic to represent binary computer instructions.

We will use the same technique to make the discussion of the micro-program easier to follow.

• Micro assembler code:

As you know, a micro-instruction instruct the datapath to perform some operation.

We have seen for example, that the micro-instruction:

```        00000000 00010101 00100001 00000000
```
instructs to simple datapath to add R1 and R2 together and store the sum in register R5:

If you don't see it, here is the break down of the instruction:

```   0  00   00  00  0   0   0  0  1   0101  0010  0001  00000000
AMux Cond ALU Shf MBR MAR RD WR ENC  C     B     A    next addr
```

The net effect of this micro-instruction is:

```   R5 := R1 + R2;
```
and this notation is a lot "easier" to comprehend.

• The micro assembler code

We will use the following nmemonic to denote micro-instructions:

 ``` [dest := src1 [OP src2];] ... [lshift;|rshift;] [rd|wr;] [MAR;] [MBR;] [[if COND] goto ADDRESS;] ```

Explaination:

• The brackets [ ] indicate optional parts.

• The dots ... indicate that you can repeat the option again.

 The only repeatable option is: dest := src1 [OP src2]]

• dest := src1 [OP src2]; means:

 Store the value src1 [OP src2] in dest

Examples:

 ``` R6 := R1 + R2; MBR := R2; MAR := R5; ```

• lshift; means:

 Make the shifter perform a left shift operation

rshift; means:

 Make the shifter perform a right shift operation

(Only one of the shifts can be performed, not both)

• rd; means:

 Send a read memory request to the memory

wr; means:

 Send a write memory request to the memory

(Only one of the rd/wr can be performed, not both)

• MAR means:

 Enable the MAR register (i.e., the MAR register will receive a clock signal during Phase 3 (and will be updated)

• MBR means:

 Enable the MBR register (i.e., the MBR register will receive a clock signal during Phase 4 (and will be updated)

• if COND goto ADDRESS; means:

Note:

• It is possible to update 2 destinations in 1 micro-instruction

E.g.: update the MAR (with R2) and MBR (with R5) in the following micro-instruction:

• Some examples nmemonics of mirco-assembler instruction :

• Example 1:

 ``` Binary: (32 bits) 00000000 00010101 00100001 00000000 or: (tagged by its function name) 0 00 00 00 0 0 0 0 1 0101 0010 0001 00000000 AMux Cond ALU Shf MBR MAR RD WR ENC C B A next addr ```

is transcribed to the micro assembler instruction:

 ``` R5 := R1 + R2 ```

• Example 2:

 ``` Binary: 00010001 10100000 00100001 00000000 or: 0 00 10 00 1 1 0 1 0 0000 0010 0001 00000000 AMux Cond ALU Shf MBR MAR RD WR ENC C B A next addr ```

is transcribed to the micro assembler instruction:

 ``` mar := r2; mbr := r1; wr; ```

In plain English: it instructs the datapath to copy register R2 to MAR, copy register R1 to MBR and start a memory WRITE operation.

BTW: You have seen this instruction before and in case you don't recall this instruction: click here .

• Using the "micro assembler code", I can show you how the CPU performs the instruction execution cycle....

• However.... I need to discuss one more piece of information before I can do that...