Lab 7 - Introduction to Microprogramming

Consider the microprogrammed computer below:

  • Accumulator Based Architecture:
    DemoComputerACC.jpg

  • Complete ALU:
    ALU.jpg

The machine:

Micro Control Word - 20 bits

19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Unused Instruction
Decode
Uncond Neg Zero Fetch Write Read ALU
Reg
ACC PC MDR MAR Carry ALU
Func
  • Jump bits 16-13
    • 16 - Instruction decode, jump go address XXXX0000 where XXXX is opcode
    • 15 - Unconditional branch to fetch next instruction
    • 14 - branch to fetch next instruction on ALU output negative
    • 13 - branch to fetch next instruction on ALU output Zero
  • Memory Access 12-10
    • 12 - Fetch: IR <- MEM[PC], PC=PC+1
    • 11 - Write: MEM[MAR] <- MDR;
    • 10 - Read: MDR <- MEM[MAR]
  • ALU IN 9-8
    • 00 - IR
    • 01 - MDR
    • 10 - PC
  • Register Load 7-4
    • 7 - ACC
    • 6 - PC
    • 5 - MDR
    • 4 - MAR
  • Carry 3
  • ALU Function 2-0
    • 000 - A^B
    • 001 - AvB
    • 010 - B'
    • 011 - A+B+Cin
    • 100 - A
    • 101 - B
    • 110 - -A
    • 111 - B-A

Instructions

Opcode Dec Mnemonic Meaning Address
0000 0 HALT Stop execution 0
0001 1 ADD add_ ACC <- ACC + mem( _add) 16
0010 2 LOAD add_ ACC <- mem( _add) 32
0011 3 STORE add_ Mem( _add) <- ACC 48
0100 4 LOADI n ACC ← IR(0-7) 64
0101 5 JMP add Jump to Address add 80
0110 6 BEQ add Branch to Address if ACC = 0 96
0111 7 CLRA Clear ACC 112
1000 8 NOT ACC ← NOT(ACC) 128
1001 9 NEG ACC <- -ACC 144
1010 10 SUB add_ ACC <- mem( _add) – ACC 160
1011 11 AND add ACC <- ACC ^ mem(add) 176
1100 12 NOP No operation 192
1101 13 ??? Future Expansion 208
1110 14 ??? Future Expansion 224
1111 15 ??? Future Expansion 240

Instruction Format

OP CODE 4 Address (8)

Microcode Assembler

Rather than program the bits by hand, we can use a program called a "Microcode assembler" to convert from a symbolic form, to the bit form.

The program "mcasm" is such a program, found here: mcasm - A Microcode Assembler.

This program lets you simply assign symbolic names for the bits in the microprogram, and then use the symbols to program the code.

For example:

// ALU Operation
signal ^ACC	= ................0000;
signal vACC   	= ................0001;
signal NOT(ACC) = ................0010;
signal +ACC   	= ................0011;
signal +ACC+1 	= ................1011;
signal COPY  	= ................0100;
signal ACC    	= ................0101;
signal Neg  	= ................0110;
signal ACC-   	= ................0111;
// Register Load
signal MAR<=  	= ...............1....;
signal MDR<=  	= ..............1.....;
signal PC<=   	= .............1......;
signal ACC<=   	= ............1.......;
// ALU IN
signal IR   	= ..........00........;
signal MDR  	= ..........01........;
signal PC   	= ..........10........;
// Memory Operations
signal READ     = .........1....1.....;
signal WRITE    = ........1...........;
signal FETCH    = .......1............;

// Branch (to fetch next instruction)
signal BRZERO   = ......1.............;
signal BRNEG    = .....1..............;
signal NEXTINST = ....1...............;
signal DECODE	= ...1................;

This defines the bits and the commands. Now here is code for the add instruction:

// Fetch and decode the instruction
      FETCH;
      DECODE;

// do the ADD
      COPY,MAR<=,IR;
      READ;
      ACC<=,MDR,+ACC;
      NEXTINST;

The FETCH grabs the word pointed at by the PC, and puts it in the IR. The DECODE uses the instruction opcode to send the microprogram to the appropriate instruction (like a case statement, more below).

The ADD code gets the address part of the instruction, and puts it in the MAR. It then reads that words into the MDR. The contents of the MDR are then added to the ACC. Last NEXTINST sends the program back to fetch the next instruction.

Here is the full microcode program (for fetch and add):

  • MVNU-ACC.mc: Initial Microcode program for the accumulator based architecture (MVNU-ACC)
  • MVNU-ACC2.mc: Microcode with ADD and STORE

Instruction Decoding

The system assumes the you are using a portion of the instruction as a opcode, and assumes that the opcode plus 1 or more lower order bits (which start as zero) to give space for implementing the instructions. In our case, the code:

// 8-bit ucode address, 4 opcode, 4 lower bits (16 locations per opcode)
cond OP:4;    // Opcode
cond uaddr:4;

means that the for opcode BBBB, BBBB will be the top 4 bits of the address, and 0000 will be the bottom, and (since there are 4 lower bits) there are 16 locations before the next instruction microcode. Thus:

  • The memory for coding for ADD (0001) will start at address 0001000 (16) and go to 00011111 (31)
  • The memory for coding for BEQ (0110) will start at address 0110000 (96) and go to 01101111 (111)
  • etc.

Running MCASM

If you have a Linux system, you should be able to run mcasm directly with Python using the command below. If you don't you can either use the CSserver, or Windows with CYGWIN.

Here is how to run to run on the CS server.
  1. login to cs.mvnu.edu
  2. "mkdir CSC3054"
  3. "cd CSC3054"
  4. "cp /home/class/CSC3054/mcasm_1.1.tar.gz . "
  5. "tar -zxvf mcasm_1.1.tar.gz"
  6. "cd mcasm-1.0"
  7. "mcasm -h"
  8. A help message should print. If so you got it!
  9. Now copy the microcode file: "cp /home/class/CSC3054/MVNU-ACC.mc . "
  10. Use the command below to run,
Running on a Windows Machine

The easiest solution is to install "cygwin" an enviornment that allows you to run the full Linux/Unix universe of open source solution on Windows. It's actually pretty nice, and worth having.

  1. Go to www.cygwin.com and download and run "setup.exe"
  2. In the software install menu, find the Python iterpreter, and install.
  3. You may also need to find and install cpp.
  4. There are MVNU other useful tools you may want, but don't need for this (ssh, scp, x-windows,...)
  5. In a shell go to the directory containg both "mcasm" and the "MVNU-ACC.mc" files. You will need to "cd /cygdrive/c" to get to your c drive.
  6. Use the command below

MCASM is now run by the command:

  • "python mcasm -d -v -s MVNU-ACC.mc"

This will produce the output of ALL the memory. For the program above, the first output is for the code:

OP:0000 uaddr:0000 : 000000000001000000000000 ; FETCH
OP:0000 uaddr:0001 : 000000010000000000000000 ; DECODE

OP:0001 uaddr:0000 : 000000000000000000010100 ; COPY,MAR<=,IR
OP:0001 uaddr:0001 : 000000000000010000100000 ; READ
OP:0001 uaddr:0010 : 000000000000000110000011 ; ACC<=,MDR,+ACC
OP:0001 uaddr:0011 : 000000001000000000000000 ; BR

This show the opcode, and lower four bit address (uaddr) and bits. Of course getting HEX is better. so this is followed by a complete memory map, with the important parts being:

000000: 00 10 00 ; 00000000 => 00001000000000000 
000001: 01 00 00 ; 00000001 => 10000000000000000 
000002: 00 00 00 ; ------------ => 00000000000000000 
000003: 00 00 00 ; ------------ => 00000000000000000 
000004: 00 00 00 ; ------------ => 00000000000000000 
000005: 00 00 00 ; ------------ => 00000000000000000 
000006: 00 00 00 ; ------------ => 00000000000000000 
000007: 00 00 00 ; ------------ => 00000000000000000 
000008: 00 00 00 ; ------------ => 00000000000000000 
000009: 00 00 00 ; ------------ => 00000000000000000 
00000a: 00 00 00 ; ------------ => 00000000000000000 
00000b: 00 00 00 ; ------------ => 00000000000000000 
00000c: 00 00 00 ; ------------ => 00000000000000000 
00000d: 00 00 00 ; ------------ => 00000000000000000 
00000e: 00 00 00 ; ------------ => 00000000000000000 
00000f: 00 00 00 ; ------------ => 00000000000000000 
000010: 00 00 14 ; 00010000 => 00000000000010100 
000011: 00 04 20 ; 00010001 => 00000010000100000 
000012: 00 01 83 ; 00010010 => 00000000110000011 
000013: 00 80 00 ; 00010011 => 01000000000000000 
Here we can see the address to the left, followed by the HEX byte codes. That what we need for out memory in the machine!

Step 1

  • Write micro code for the rest of the machine. Design a simple program to test of the instructions.
  • Hint: Write, than test, one operation at a time.
  • Turn in you microcode, and your complete test program.
  • Demonstrate for the instrutor for full credit.

Step 2

  • Write a program to sum the squares from 1 to N, where N is able to set prior to running the program.
  • Enter the program, and test for several values of N
  • Turn in the commented code.
  • Demonstrate for the instructor.

*

Topic attachments
I Attachment Action Size Date Who Comment
Jpgjpg ALU.jpg manage 57.0 K 2012-11-06 - 15:23 JimSkon Complete ALU
Jpgjpg DemoComputerACC.jpg manage 127.1 K 2012-11-06 - 15:22 JimSkon Accumulator Based Architecture
Circcirc DemoSystemACC.circ manage 34.8 K 2012-11-07 - 17:25 JimSkon Updated Machine
Circcirc DemoSystemACCClock.circ manage 37.7 K 2012-11-13 - 22:03 JimSkon Accumulator Based Architecture with Clock
Mcmc MVNU-ACC.mc manage 3.2 K 2012-11-13 - 22:10 JimSkon Microcode with add
Mcmc MVNU-ACC2.mc manage 3.3 K 2012-11-13 - 22:10 JimSkon Microcode with add and Load
Topic revision: r6 - 2012-11-20 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback