CS 366 - Mythsim Microprogram Assignment

Solution submitted by one of the groups in the class

Note: in the Mythsim simulator, the c_out status line actually contains the inverted value of the carry out instead of the straight (non-complimented) value of the carry out.

You are to work in groups of 2 or 3 students for this assignment. Working in groups is required for the assignment. For Part 1, the work you turn in must include the information from Part 0. For Part 2, the work you turn in must include the information from Part 0 and Part 1.

For part 1 of this assignment, your group will need to write a microprogram for the Mythsim machine for all opcodes specified below for parts 0 or 1. You will need to turn this program in electronically using the turnin command and you will to bring a hard copy of your program to class on the day it is due. For part 1, your program does not have to run on the Mythsim simulator (version 8), but you are highly encouraged to get it running on it. Here is a working Mythsim program for part 0.

For part 2, you will have to electronically turn in (via the UNIX turnin command on the CS machines) a microprogram that runs on the the MythSim simulator (release 8). This microprogram must run all opcodes as specified in this write up. Here is a working Mythsim program for part 0.

Here are two mem files, that show the machine code for the assembly language instructions for two programs. The first program just lists all of the operations for part0. The second program lists the operations to perform an assembly langauge equivelent to x = y + z.

The grading for part 2 will be done as follows:

Assignment
Part
Opcode
number
NameDescription
00no-opThis operation does nothing
01addRi ← Rj + Rk

This operation will add the values from registers Rj and Rk and store the result in resiter Ri.

02set registerRi ← Const8

This operation will store in register Ri the constant value given in the last 8 bits of the instruction register.

03Branch if zeroif (Rj == 0) then PC ← PR + Const4

This instruction will check if the value in register Rj is zero. If so, it will add the 4 bit constant value from the instruction register to the PC.

04moveRi ← Rj

This instruction will take the value in register Rj and store it in register Ri.

05StoreMem[Rj] ← Rk

This instruction will take a value in register Rk and store it in the computer's memory. The memory address is given by the value in register Rj.

06LoadRi ← Mem[Rj]

This instruction will take a value from the computer's memory and store it in register Ri. The memory address is given by the value in register Rj.

07SubtractionRi ← Rj - Rk

This operation will subtract from the value in register Rj the value in register Rk and store the result in resiter Ri.

18Bitwise ORRi ← Rj | Rk

This operation will perform a BITWISE OR (each bit position is ORed independently of the other bit positions). It will or each bit of the value in register Rj with the value in register Rk and store the result in register Ri.

19Bitwise ANDRi ← Rj & Rk

This operation will perform a BITWISE AND (each bit position is ANDed independently of the other bit positions). It will and each bit of the value in register Rj with the value in register Rk and store the result in register Ri.

110Bitwise NOTRi ← ¬ Rj

This operation will perform a BITWISE NOT (each bit position is NOTed independently of the other bit positions). It will not (invert) each bit of the value in register Rj and store the result in register Ri.

211Bitwise XORRi ← Rj \305 Rk

This operation will perform a BITWISE XOR (each bit position is XORed independent of the other bit positions). It will XOR each bit of the of the value in register Rj with the corresponding bit of the valus in register Rk and store the result in register Ri.

212Bitwise NORRi ← ¬ (Rj | Rk)

This operation will perform a BITWISE NOR (each bit position is NORed independent of the other bit positions). It will NOR each bit of the of the value in register Rj with the corresponding bit of the valus in register Rk and store the result in register Ri.

113IncrementRi ← Rj + Const4

This operation will add to the value in regsiter Rj the sign extented value contained in the Const4 field of the instruction register and store this result in register Ri. Note the sign extention of the 4 bit constant value is automatically done by the machine.

114NegationRi ← -Rj

This operation will change the sign on the value in register Rj and store the result in register Ri.
In effect this operation performs: Ri ← 0 - Rj.

115Logical Left ShiftRi ← Rj<<Rk

This operation will shift the value in register Rj to the left by the number of bits equal to the value in register Rk. The result will be stored in register Ri. The value is filled in with zeros for each bit position shifted. Note that if the value in register Rk is 8 or greater, the result will be all zeros. The value in Rk is assumed to be greater than or equal to zero. If the value in Rk is negative, do something reasonable (leave the value unshifted, set the value to zero, etc).

216Logical Right ShiftRi ← Rj>>Rk

This operation will shift the value in register Rj to the right by the number of bits equal to the value in register Rk. The result will be stored in register Ri. The value is filled in with zeros for each bit position shifted. Note that if the value in register Rk is 8 or greater, the result will be all zeros. The value in Rk is assumed to be greater than or equal to zero. If the value in Rk is negative, do something reasonable (leave the value unshifted, set the value to zero, etc).

217Arithmetic Right ShiftRi ← Rj>>Rk

This operation will shift the value in register Rj to the right by the number of bits equal to the value in register Rk. The result will be stored in register Ri. The value is filled in with zeros or ones depending on the sign bit of the original value in Rj. The sign bit is the most significant bit (the leftmost). If the sign bit is zero, the shifted value is filled in with zeros. If the sign bit is one, the shifted value is filled in with ones. Note that if the value in register Rk is 8 or greater, the result will be all zeros or all ones (depending on the sign bit of the original value in Rj. The value in Rk is assumed to be greater than or equal to zero. If the value in Rk is negative, do something reasonable (leave the value unshifted, set the value to zero, etc).

218Circullar Left ShiftRi ← Rj<<Rk

This operation will circular shift the value in register Rj to the left by the number of bits equal to the value in register Rk. The result will be stored in register Ri. For each position shifted, the value is filled in with a zero if the bit value shifted out was zero and the value is filled in with a one if the value shifted out was one. Note that if the value in register Rk is a multiple of 8, the result will be the original value. The value in Rk is assumed to be greater than or equal to zero. If the value in Rk is negative, do something reasonable (leave the value unshifted, etc).

1 219MultiplicationRi ← Rj * Rk

This operation will multiply the value in register Rj by the value in register Rk and store the result in register Ri. Only the lower 8 bits of the result is stored in register Ri. Do not worry about overflow.

220DivisionRi ← Rj / Rk

This operation will divide the value in register Rj by the value in register Rk and store the integer quotent in register Ri.

221RemainderRi ← Rj % Rk

This operation will divide the value in register Rj by the value in register Rk and store the integer remainder in register Ri.

222Bit SetRi ← Rj with the Rk-th bit of Rj set to one

If the value in register Rk is outside of the range from 0 to 7, the operation is the same as a move operations (see opcode 4). In other words, when the value in register Rk is outside of the range from 0 to 7, the value in Rj is stored as is into register Ri.

223Bit ClearRi ← Rj with the Rk-th bit of Rj cleared to zero

If the value in register Rk is outside of the range from 0 to 7, the operation is the same as a move operations (see opcode 4). In other words, when the value in register Rk is outside of the range from 0 to 7, the value in Rj is stored as is into register Ri.

224Bit InvertRi ← Rj with the Rk-th bit of Rj inverted

If the value in register Rk is outside of the range from 0 to 7, the operation is the same as a move operations (see opcode 4). In other words, when the value in register Rk is outside of the range from 0 to 7, the value in Rj is stored as is into register Ri.

225Branch if Bit Setif (the Rk-th bit of Rj == 1) then PC ← PC + Const4

If the value in register Rk is outside of the range from 0 to 7, the operation does not branch (the program counter is not changed).

126Branch if equalif (Rj == Rk) then PC ← PC + Const4

If the value in register Rj is equal to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

127Branch if not equalif (Rj != Rk) then PC ← PC + Const4

If the value in register Rj is not equal to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

228Branch if less thanif (Rj < Rk) then PC ← PC + Const4

If the value in register Rj is less than to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

229Branch if less than or equalif (Rj <= Rk) then PC ← PC + Const4

If the value in register Rj is less than or equal to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

230Branch if greater thanif (Rj > Rk) then PC ← PC + Const4

If the value in register Rj is greater than to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

231Branch if greater than or equalif (Rj >= Rk) then PC ← PC + Const4

If the value in register Rj is greater than or equal to the value in register Rk, it will add the 4 bit constant value from the instruction register to the program counter.

232Branch if less than zeroif (Rj < 0) then PC ← PC + Const4

The the value in register Rj is less than zero, add the 4 bit constant value from the instruction register to the program counter.

233Branch if greater than zeroif (Rj > 0) then PC ← PC + Const4

The the value in register Rj is greater than zero, add the 4 bit constant value from the instruction register to the program counter.

234Branch if less than or equal to zeroif (Rj <= 0) then PC ← PC + Const4

The the value in register Rj is less than or equal to zero, add the 4 bit constant value from the instruction register to the program counter.

235Branch if greater than or equal to zeroif (Rj >= 0) then PC ← PC + Const4

The the value in register Rj is greater than or equal to zero, add the 4 bit constant value from the instruction register to the program counter.

236Branch if not zeroif (Rj != 0) then PC ← PC + Const4

The the value in register Rj is not equal to zero, add the 4 bit constant value from the instruction register to the program counter.

237Jump with ConstantPC ← Const8

Store in the program counter (register 7) the value in the 8 bit constant field in the instruction.

238Jump with RegisterPC ← Rj

Store in the program counter (register 7) the value from register Rj.

239Jump to SubroutineRi ← PC ; PC ← Const8

First, store the current value of the program counter (register 7) in register Ri. Then, store in the program counter (register 7) the value in the 8 bit constant field in the instruction.

240Return from SubroutinePC ← Rj

Store in the program counter (register 7) the value from register Rj.

141HaltStop exectution

In Mythsim, execution is halted when the machine detects a microinstruction that does a goto to itself. The microinstruction for this is:

opcode[41]: goto opcode[41];

Remember that the instruction has two formats. The first format is:
Opcode    
6 bits
Ri
2 bits
Rj
2 bits
Rk
2 bits
Const4
4 bits
The second format is:
Opcode    
6 bits
Ri
2 bits
Const8                
8 bits

Below is a table showing how to check for a comparison between to values. Remember, to compare A with B, look at the result of A - B. The comparision uses the following pieces of information:

Comparison
Operation
equivalent to
A > B !z && (s == v)
A >= B s == v
A < B s XOR v
A >= B z || (s XOR v)
A == B z
A != B !z