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 electronically turn in (via turnin) your assignment using the project name of mp4. Each group should only submit one copy of the assignment. Make sure that the assignment includes the names and UIC email addresses of all members of the group in a header comment. Here is a working Mythsim program for part 0.
For part 2 of this assignment, your group will need to write a microprogram must run all opcodes as specified in this write up. You will need to electronically turn in (via turnin) your assignment using the project name of mp5. Each group should only submit one copy of the assignment. Make sure that the assignment includes the names and UIC email addresses of all members of the group in a header comment.
Here are two mem files, that show the machine code for the assembly language instructions for two programs.
The grading for part 2 will be done as follows:
The biggest change for Part 2 of MP 5, is that we will incorporate a program stack to allow for function calls to be made with the assembly language. We will use register 6 for the stack pointer. In the following descriptions we refer to the stack pointer as "SP". This means that register 6 cannot be used as a temp register as was done in Part 0 and Part 1 of the assignment. You will, therefore, need to rewrite your code from Part 1 to change to any use of r6 to another temp register. For example the fetch0, fetch1, fetch2 and fetch3 statements must be rewritten. One possible rewriting could be as follows (which uses register 5 instead of register 6):
fetch0: a_sel=7, b_sel=7, alu_sel=AND, r5_write, mar_sel=LOAD; fetch1: a_sel=5, alu_sel=ADDA, c_in, r7_write, read, ir0_sel=LOAD, if wait then goto fetch1 else goto fetch2 endif; fetch2: a_sel=7, b_sel=7, alu_sel=AND, r5_write, mar_sel=LOAD; fetch3: a_sel=5, alu_sel=ADDA, c_in, r7_write, read, ir1_sel=LOAD, if wait then goto fetch3 else goto fetch4 endif;If your program needs more that two temp registers (r4 and r5) to implement the microcode statements for a particular assembly language instruction (like multiplication), you can save the values from registers r0 through r3 onto the stack towards the beginning of the microcode statements for this assembly language instruction and restore them from the stack toward the end of the microcode statements for this assembly language instruction. Since efficiency is being considered for your grade, only save and restored the minimum number of registers. It is not a good idea to mess with the values in r6 (the stack pointer) or in r7 (the program counter).
Your microcode will also need to initialize the value in register 6 to "just beyond" the last possible address in memory. The stack pointer is to always point to the top memory position on the stack. To push a value onto the stack, decrement r6 and then store the value into memory at the current address referred to by r6. To pop a value from the stack, load the value from memory at the current address referred to by r6 and then increment r6.
Assignment Part | Opcode number | Name | Description |
---|---|---|---|
0 | 0 | no-op | This operation does nothing |
0 | 1 | add | Ri ← Rj + Rk
This operation will add the values from registers Rj and Rk and store the result in resiter Ri. |
0 | 2 | set register | Ri ← Const8
This operation will store in register Ri the constant value given in the last 8 bits of the instruction register. |
0 | 3 | Branch if zero | if (Rj == 0) then PC ← PC + 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. |
1 | 3 | Branch if zero | if (Rj == 0) then PC ← PC + (2 * Const4)
This instruction will check if the value in register Rj is zero. If so, it will add two times the 4 bit constant value from the instruction register to the PC. |
0 | 4 | move | Ri ← Rj
This instruction will take the value in register Rj and store it in register Ri. |
0 | 5 | Store | Mem[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. |
0 | 6 | Load | Ri ← 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. |
0 | 7 | Subtraction | Ri ← Rj - Rk
This operation will subtract from the value in register Rj the value in register Rk and store the result in resiter Ri. |
0 | 8 | Halt | Stop exectution
In Mythsim, execution is halted when the machine detects a microinstruction that does a goto to itself. The microinstruction for this is: opcode[8]: goto opcode[8]; |
1 | 9 | Bitwise OR | Ri ← 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. |
1 | 10 | Bitwise AND | Ri ← 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. |
1 | 11 | Bitwise NOT | Ri ← ¬ 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. |
1 | 12 | Bitwise XOR | Ri ← 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. |
1 | 13 | Increment | Ri ← 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. |
1 | 14 | Negation | Ri ← -Rj
This operation will change the sign on the value in register Rj
and store the result in register Ri. |
1 | 15 | Logical Left Shift | Ri ← 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). |
2 | 16 | Logical Right Shift | Ri ← 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). |
2 | 17 | Arithmetic Right Shift | Ri ← 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). |
1 | 18 | Multiplication | Ri ← 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. |
2 | 19 | Division | Ri ← 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. |
2 | 20 | Remainder | Ri ← 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. |
1 | 21 | Branch if equal | if (Rj == Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is equal to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
1 | 22 | Branch if not equal | if (Rj != Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is not equal to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 23 | Branch if less than | if (Rj < Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is less than to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 24 | Branch if less than or equal | if (Rj <= Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is less than or equal to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 25 | Branch if greater than | if (Rj > Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is greater than to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 26 | Branch if greater than or equal | if (Rj >= Rk) then PC ← PC + (2 * Const4)
If the value in register Rj is greater than or equal to the value in register Rk, it will add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 27 | Branch if less than zero | if (Rj < 0) then PC ← PC + (2 * Const4)
The the value in register Rj is less than zero, add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 28 | Branch if greater than zero | if (Rj > 0) then PC ← PC + (2 * Const4)
The the value in register Rj is greater than zero, add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 29 | Branch if less than or equal to zero | if (Rj <= 0) then PC ← PC + (2 * Const4)
The the value in register Rj is less than or equal to zero, add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 30 | Branch if greater than or equal to zero | if (Rj >= 0) then PC ← PC + (2 * Const4)
The the value in register Rj is greater than or equal to zero, add two times the 4 bit constant value from the instruction register to the program counter. |
2 | 31 | Branch if not zero | if (Rj != 0) then PC ← PC + (2 * Const4)
The the value in register Rj is not equal to zero, add two times the 4 bit constant value from the instruction register to the program counter. |
1 | 32 | Jump with Constant | PC ← Const8
Store in the program counter (register 7) the value in the 8 bit constant field in the instruction. |
1 | 33 | Jump with Register | PC ← Rj
Store in the program counter (register 7) the value from register Rj. |
2 | 34 | Stack Adjust | SP ← SP + CONST8
Change the stack pointer to either allocate or deallocate space on the stack. |
2 | 35 | Store onto Stack | Mem[SP + CONST4] ← Rk
Store a value from register Rk onto the stack adjusted by the CONST4 value. |
2 | 36 | Load from Stack | Ri ← Mem[SP + CONST4]
Load a value from the stack adjusted by the CONST4 value into register Ri. |
2 | 37 | Store onto Stack | Mem[SP + Rj] ← Rk
Store a value from register Rk onto the stack adjusted by the value in register Rj. |
2 | 38 | Load from Stack | Ri ← Mem[SP + Rj]
Load a value from the stack adjusted by the value in register Rj into register Ri. |
2 | 39 | Push |
SP ← SP - 1
Mem[SP] ← Rj Push the value of register Rj onto the stack. |
2 | 40 | Pop |
Ri ← Mem[SP]
SP ← SP + 1 Pop the value from the stack and store it into register Ri. |
2 | 41 | Jump to Subrountine |
SP ← SP - 1
Mem[SP] ← PC PC ← CONST8 This operation is to perform a jump to subroutine in which the return address (the current PC value) is pushed directly onto the stack. After the return address is saved on the stack, the address of the subroutine is stored in the program counter (register 7). The address of the subroutine is given in the 8 bit constant field in the instruction. |
2 | 42 | Return from Subroutine |
PC ← Mem[SP]
SP ← SP + 1 This operation is to perform a return from subroutine in which the return address is assumed to the top value on the program stack. The return address is to be popped from the stack and stored in the program counter (register 7). The stack pointer will be register 6. |
Remember that the instruction has two formats.
Opcode 6 bits | Ri 2 bits | Rj 2 bits | Rk 2 bits | Const4 4 bits |
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 |