CS355 Sylabus

# The Complete Micro-Program

• The complete micro-program in micro assembler code is as follows:

 ```ADDR Micro Assembler Instruction Comment =========================================================================== 0: mar := pc; rd; {main loop} 1: pc := pc + 1; rd; mbr; {increment pc, MBR} 2: ir := mbr; if n then goto 31; {save, decode mbr} 3: tir := lshift(ir + ir); if n then goto 22; 4: tir := lshift(tir); if n then goto 13; {000x or 001x?} 5: alu := tir; if n then goto 9; {0000 or 0001?} 6: mar := ir; rd; {0000 = LODD} 7: rd; mbr; 8: ac := mbr; goto 0; 9: ir := ir and r8; 10: mar := ir; mbr := ac; wr; {0001 = STODD} 11: wr; goto 0; 12: alu := tir; if n then goto 17; {0010 or 0011?} 13: ir := ir and r8; 14: mar := ir; rd; {0010 = ADDD} 15: rd; mbr; 16: ac := mbr + ac; goto 0; 17: ir := ir and r8; 18: mar := ir; rd; {0011 = SUBD} 19: ac := ac + 1; rd; {Note: x-y = x+1+\y} 20: a := inv(mbr); 21: ac := ac + a; goto 0; 22: tir := lshift(tir); if n then goto 25; {010x or 011x?} 23: alu := tir; if n then goto 23; {0100 or 0101?} 24: alu := ac; if n then goto 27; {0100 = JPOS} 25: pc := band(ir, amask); goto 0; {perform the jump} 26: alu := ac; if z then goto 22; {0101 = JZER} 27: goto 0; {jump failed} 28: alu := tir; if n then goto 27; {0110 or 0111?} 29: pc := band(ir, amask); goto 0; {0110 = JUMP} 30: ac := band(ir, amask); goto 0; {0111 = LOCO} 31: tir := lshift(ir + ir); if n then goto 40; {10xx or 11xx?} 32: tir := lshift(tir); if n then goto 35; {100x or 101x?} 33: alu := tir; if n then goto 33; {1000 or 1001?} 34: a := ir + sp; {1000 = LODL} 35: mar := a; rd; goto 7; 36: a := ir + sp; {1001 = STOL} 37: mar := a; mbr := ac; wr; goto 10; 38: alu := tir; if n then goto 38; {1010 or 1011?} 39: a := ir + sp; {1010 = ADDL} 40: mar := a; rd; goto 13; 41: a := ir + sp; {1011 = SUBL} 42: mar := a; rd; goto 16; 43: tir := lshift(tir); if n then goto 46; {110x or 111x?} 44: alu := tir; if n then goto 44; {1100 or 1101?} 45: alu := ac; if n then goto 22; {1100 = JNEG} 46: goto 0; 47: alu := ac; if z then goto 0; {1101 = JNZE} 48: pc := band(ir, amask); goto 0; 49: tir := lshift(tir); if n then goto 50; 50: sp := sp + (-1); {1110 = CALL} 51: mar := sp; mbr := pc; wr; 52: pc := band(ir, amask); wr; goto 0; 53: tir := lshift(tir); if n then goto 65; {1111, examine addr} 54: tir := lshift(tir); if n then goto 59; 55: alu := tir; if n then goto 56; 56: mar := ac; rd; {1111000 = PSHI} 57: sp := sp + (-1); rd; 58: mar := sp; wr; goto 10; 59: mar := sp; sp := sp + 1; rd; {1111001 = POPI} 60: rd; 61: mar := ac; wr; goto 10; 62: alu := tir; if n then goto 62; 63: sp := sp + (-1); {1111010 = PUSH} 64: mar := sp; mbr := ac; wr; goto 10; 65: mar := sp; sp := sp + 1; rd; {1111011 = POP} 66: rd; mbr; 67: ac := mbr; goto 0; 68: tir := lshift(tir); if n then goto 73; 69: alu := tir; if n then goto 70; 70: mar := sp; sp := sp + 1; rd; {1111100 = RETN} 71: rd; mbr; 72: pc := mbr; goto 0; 73: a := ac; {1111101 = SWAP} 74: ac := sp; 75: sp := a; goto 0; 76: alu := tir; if n then goto 76; 77: a := band(ir, smask); {1111110 = INSP} 78: sp := sp + a; goto 0; 79: a := band(ir, smask); {1111111 = DESP} 80: a := inv(a); 81: a := a + 1; goto 75; ```

• Fear not !!!. It looks complicated, but once you understand the logic, it is very simple.

• To make things really simple, I have made lots of pictures to guide you through the micro-program (in the next webpage).

• But always remember the purpose of the micro-program:

 To execute a machine instruction (encoded in bits) The meaning of the machine instruction were discussed here: click here

• Also, remember the steps that the CPU goes through to execute an machine (assembler) instruction: click here

 Fetch the next instruction from the memory location given by the program counter (into the instruction register) Decode the instruction (stored in the instruction register) Fetch the operands Execute the instruction

This is called the instruction execution cycle

 You will see that the micro-program is in fact the instruction execution cycle loop

BTW: The code given above are the symbolic representation of the micro-instructions. The actual instructions are bit patterns

You would see this in the real ROM (decimal dump of the binary numbers):

 ``` 16 192 0 0 1 80 96 0 176 19 0 31 36 20 51 22 52 20 4 13 48 0 4 9 16 192 48 0 17 64 0 0 240 17 0 0 8 19 131 0 17 160 49 0 112 32 0 0 48 0 4 17 8 19 131 0 16 192 48 0 17 64 0 0 224 17 16 0 8 19 131 0 16 192 48 0 0 81 97 0 152 26 0 0 96 17 161 0 52 20 4 25 48 0 4 23 48 0 1 27 104 16 131 0 80 0 1 22 112 0 0 0 48 0 4 27 104 16 131 0 104 17 131 0 36 20 51 40 52 20 4 35 48 0 4 33 0 26 35 0 112 192 160 7 0 26 35 0 113 160 161 10 48 0 4 38 0 26 35 0 112 192 160 13 0 26 35 0 112 192 160 16 52 20 4 46 48 0 4 44 48 0 1 22 112 0 0 0 80 0 1 0 104 16 131 0 52 20 4 50 0 18 114 0 17 160 32 0 104 48 131 0 52 20 4 65 52 20 4 59 48 0 4 56 16 192 16 0 0 82 114 0 112 160 32 10 0 210 98 0 16 64 0 0 112 160 16 10 48 0 4 62 0 18 114 0 113 160 33 10 1 210 98 0 16 64 0 0 240 17 0 0 52 20 4 73 48 0 4 70 0 210 98 0 17 64 0 0 240 16 0 0 16 26 1 0 16 17 2 0 112 18 10 0 48 0 4 76 8 26 147 0 96 18 162 0 8 26 147 0 24 26 10 0 96 26 106 75 0 0 0 0 ... (filler) ```

Credit: this numeric code was obtain from Phil Hutto. He converted the Micro-assembler program into binary machine code one time when he taught CS355.