CS 355 - Computer Organization/Architecture II
Project 4

Due: See Class Webpage.

0. Project Preparation

• Make a project sub-directory and copy the prepared files:

 mkdir ~/cs355/pj4 cp /home/cs355001/Handouts/pj4/* ~/cs355/pj4

You will copy these files:

 basic.h - the commonly used circuit components in the CS355 projects Full_Adder aa c_in a b | c_out sum; Decoder2x4 aa c[1..0] | s[3..0]; You can use the Full_Adder and the 2x4 decoder components in project pj3 help-CLK - the main simulation program file to test the CLK circuit It creates switches and probes to help you test the CLK circuit (macro) that you must make in this project help-MPC - the main simulation program file to test the MPC circuit It creates switches and probes to help you test the MPC circuit (macro) that you must make in this project clock.h - Skeletal project file - contains the circuits (macro definitions) that you must make for this project sample-mux - Sample EDiSim program to show you how to use the Mux built-in circuit sample-Dff - Sample EDiSim program to show you how to use the Dff built-in circuit

• You will need to learn to use the Mux (multiplexor) built-in component to do this project:

• Syntax:

 Mux coord N-controls | 2^N inputs | 1 output ; Inputs and outputs can be arrays of signals !!!

Examples:

 Mux aa sel | B A | out; // Mux has 1 select signal, so you need to use 2 inputs (and 1 output) // If sel = 0 then out = A // If sel = 1 then out = B Mux aa sel[1..0] | D C B A | out; // Mux has 2 select signals, so you need to use 4 inputs (and 1 output) // If sel[1] = 0 and sel[0] = 0 then out = A // If sel[1] = 0 and sel[0] = 1 then out = B // If sel[1] = 1 and sel[0] = 0 then out = C // If sel[1] = 1 and sel[0] = 1 then out = D Mux aa sel[1..0] | D[3..0] C[3..0] B[3..0] A[3..0] | out[3..0]; // You can use arrays (e.g.: A[3..0]) as inputs and outputs of the Mux // If sel[1] = 0 and sel[0] = 0 then out[3..0] = A[3..0] // I.e.: out[3] = A[3], out[2] = A[2], out[1] = A[1] and out[0] = A[0] // If sel[1] = 0 and sel[0] = 1 then out[3..0] = B[3..0] // If sel[1] = 1 and sel[0] = 0 then out[3..0] = C[3..0] // If sel[1] = 1 and sel[0] = 1 then out[3..0] = D[3..0] // The ability to switch an array of signals will help when // you connect the registers to the ALU later in project 6

Try: cs355sim sample-mux to see the operation of the built-in Mux circuit

• You will need to learn to use the Dff (D-flipflop) built-in component to do this project:

• Syntax:

 Dff coord set input clk reset output ; If set = ONE and reset = ZERO, then output = ONE ("set") If set = ZERO and reset = ONE, then output = ZERO ("reset") If set = ZERO and reset = ZERO, then output = input when the clk signal is clicked twice (set = ONE and reset = ONE is not used)

Examples:

 Dff bb-cb ZERO inp Clk Reset out ; // If we only want the Reset function

Try: cs355sim sample-Dff to see the operation of the built-in Dff circuit

1. Project overview

In this assignment, you will design and implement another two components for your computer, which are:

 a 4-phase clock               a Micro-Program Counter (MPC)

Both circuits are implements as macros, so you will be writing two macros for this project.

Just like in project pj3, I have provides you with 2 circuit test environment files and skeleton project program file.

Write the circuits inside the skeleton project program file

The circuit test environment program files are used to test your project

2. Project Assignment

• Part 1: Write a macro called Four_Phase_Clock that defines the 4-phase clock that was discussed in class (see more detail here: click here)

• The 4-phase clock has 4 "states" or phases.

The 4-phase clock goes through the phases as follows:

 phase 1 ----> phase 2 ----> phase 3 ----> phase 4 --+ ^ | | | +---------------------------------------------------------

• The 4-phase clock is a circuit that has 2 inputs and 4 outputs:

• The inputs are:

 Reset: used to reset the 4 phase clock to phase 1 Clk: signal used to make the 4 phase clock move to the next phase

• The outputs of the 4 phase clock are:

 Phase[0]: equal to 1 if the 4 phase clock is in phase 1, otherwise equals to 0 Phase[1]: equal to 1 if the 4 phase clock is in phase 2, otherwise equals to 0 Phase[2]: equal to 1 if the 4 phase clock is in phase 3, otherwise equals to 0 Phase[3]: equal to 1 if the 4 phase clock is in phase 4, otherwise equals to 0

The macro header of the 4 phase clock is:

 Define Four_Phase_Clock Reset Clk | Phase[3..0]; /* Write the 4-phase clock macro here */ Endef;

The inputs are as follows:

• Reset:

 When Reset = ONE, it will reset the 4-phase clock to phase (state) 1 When Reset = ZERO, the 4-phase clock will transit to the next phase (state) each time you turn the Clk signal ON and then OFF

• Clk = used to make the 4-phase clock move to the next phase (will only work when Reset = ZERO)

The output signals are as follows:

• Phase[3..0] = an array of 4 bits (signals):

 Phase[0]: equal to 1 if the 4 phase clock is in phase 1, otherwise equals to 0 Phase[1]: equal to 1 if the 4 phase clock is in phase 2, otherwise equals to 0 Phase[2]: equal to 1 if the 4 phase clock is in phase 3, otherwise equals to 0 Phase[3]: equal to 1 if the 4 phase clock is in phase 4, otherwise equals to 0

After you have written the CLK macro in the file clock.h, you can test the CLK circuit using this command:

 cs355sim help-CLK

The test circuit (help-CLK) will look as follows:

You can interact with the help-ALU test circuit as follows:

 Press a to reset the 4-phase clock (Press a again to allow the 4-phase clock to run)              Press 0 to run the 4-phase clock

• How to test your CLK circuit:

1. When the simulation starts, you will see the following state:

2. Press a: you will see the clock go to phase 1 immediately:

3. Press a again --- you need to release the reset:

The clock circuit can now run.

4. If you press 0 repeatedly and you will see:

 For every 2 presses, the 4 phase clock will advance 1 phase. You will see the light move to the left and then wrap around

You can observe the correct behavior by running this program and use the above instructions to interact with the circuit:

 /home/cs355001/Solutions/pj4-CLK

Comment:

 You will need to implement a Finite State Automatum to remember the states of the 4 phase clock More information on what to do: click here

• Part 2: Write a macro called MPC_With_Reset that implements a Micro-Program Counter circuit with a reset function.

The macro header is as follows:

 Define MPC_With_Reset Reset Clk Branch Addr[7..0] | MPC[7..0]; /* Write your MPC component here */ Endef;

The inputs of the MPC_With_Reset component are as follows:

• Reset:

 When Reset = ONE, it will reset the Micro Program Counter to 00000000 When Reset = ZERO, the MPC component will transit to the Program Counter value each time you turn the Clk signal ON and then OFF

• Clk = make the Micro Program Counter take on the next program address value

 The next program address value of the MPC depends on the branch signal !!!

• Branch: the branch indication signal

Effect:

 If Branch = 0, then the next program address value taken on by the MPC is equal to current MPC value + 1 If Branch = 1, then the next program address value taken on by the MPC is equal to the Address input value Addr[7..0]

 The MPC_With_Reset circuit will taken on the value Addr[7..0] when Branch = 1 (and you give a Clk signal to the MPC_With_Reset circuit)

The output signals of the MPC_With_Reset component are as follows:

 MPC[7..0] = 8 bits value representing the address stored in the MPC component

How to make the MPC_With_Reset component:

After you have written the MPC_With_Reset macro in the file clock.h, you can test the MPC_With_Reset circuit using this command:

 cs355sim help-MPC

The test circuit (help-MPC) will look as follows:

You can interact with the help-ALU test circuit as follows:

• Press a to reset the MPC component

• Use key 1 to select branch/no branch:

 Branch signal = 0 means: don't branch (i.e.: continue to next instruction) Then MPC will increase its address after each clock signal Branch signal = 1 means: branch to the given address Then MPC value will change the address value after a clock signal

• Use the keys 2, 3, 4, 5, 6, 7, 8, 9 to set the 8 bit (branch) address

• Key 0 is the clock signal for the MPC component

• How to test your MPC circuit:

1. When you run cs355sim help-MPC, you will see this initial state:

2. Press a (= Reset) and you will see the output MPC[7-0] go to 00000000 immediately

3. Press a again --- to release the reset so that the MPC circuit run normally.

4. While switch '1' (Branch) = 0, when you press 0 repeatedly, you will see that:

 For every 2 presses, the MPC circuit will increase by 1. (I.e.: if you don't branch, the next instruction is found in the memory location that follows the current memory address)

This simulate the fact that the CPU will fetch the next instruction located at the next memory address

5. To make the MPC branch to a memory address:

• Set the branch address using the key 2, 3, 4, 5, 6, 7, 8, 9

• Press 1 to set Branch = 1

• Then press 0 twice

 The MPC output will be equal to the branch address

You can observe the correct behavior by running this program and use the above instructions to interact with the circuit:

 /home/cs355001/Solutions/pj4-MPC

3. How to make the 4-phase clock component

The functionality of 4-phase clock has been discussed in class - refer to the teaching material: click here

The 4-phase clock emits 4 signals that is paced as follows:

The state change of the 4-phase clock is controlled manually (using key 0)

The state of the 4-phase clock can also be resetted at any time.

Recall that:

To implement the 4-phase clock, we use a 4-states Finite State Machine with the following state transitions:

The Finite State Machine will have no input signal !!! The circuit does have 2 switches that perform the following functions:

• A switch (toggled by key 1) for the reset signal:

 When the Reset signal is equal to ONE, it forces all Dffs in the 4-phase clock to ZERO. When the Reset signal is equal to ZERO, the Dff components will operate as ordinary Dffs

• A switch (toggled by key 0) that functions as the manual clock that advances the 4-phase clock.

You must first implement the Finite State Machine (FSM) given in the above figure.

After you finish the FSM, add additional combinatorial circuit (figure out what you need yourself) to translate the state of the FSM to the 4 outputs Phase[0], Phase[1], Phase[2] and Phase[3] of the clock:

 Phase[0] will only be 1 if the Finite State Machine is in state 00 Phase[1] will only be 1 if the Finite State Machine is in state 01 Phase[2] will only be 1 if the Finite State Machine is in state 10 Phase[3] will only be 1 if the Finite State Machine is in state 11

Note:

• Due to the fact that array index starts at 0, and humans starts counting at the number 1, the representation for the phases by the outputs is skewed:

 Phase[0] is the output for Phase 1 Phase[1] is the output for Phase 2 Phase[2] is the output for Phase 3 Phase[3] is the output for Phase 4

4. How to make the MPC-With-Reset circuit

The MPC-With-Reset circuit was discussed in class and the relevant material is here: click here

Schematically, the circuit looks like this:

The input parameters of the MPC_With_Reset component have the following functions:

 Reset: is used to reset the 8 Dffs of the MPC to the value 0 Branch: controls a multiplexor to select the input of the 8 Dffs used to store the value of the MPC Clk: is the clock signal of the 8 Dffs used to store the value of the MPC

5. Turn in

Turn in your "clock.h" file that contains the Four_Phase_Clock and the MPC_With_Reset components as assignment pj4 with the following command:

 /home/cs355001/turnin clock.h pj4

6. Extension requests

• Each project must be turned in before the specified dead line (see class webpage for the deadline)

• You can request upto 3 extensions in the semester without any penalties without any questions asked

(A 4th extension request will be automatically denied --- personal emergencies and illiness with documentation will receive a "free" extension)

• To request an extenion for this project, us the following command:

 /home/cs355001/req-ext pj4

Statement of Policy on Computer Assignments

Students will be graded partially on the basis of their programming assignments. These programming assignments are to be treated as examinations, and are expected to be your individual work. While discussions with other students in the course may be permitted or encouraged by your instructor, you should write your program yourself. The mathlab representatives are available to explain error messages, discuss briefly technical details with which you may not be familiar, and give short suggestions as to how you might detect logic errors. The reps should not, however be asked to write part or all of your program. Your instructor (and any teaching assistants assigned to the course) will be glad to help you to the extent that he or she feels reasonable.

Submissions based on other students solutions in prior offerings of the course specifically violate these guidelines, as do submissions prepared with the help of an outside "tutor".

You should take precautions to protect the confidentiality of your work: preserve the secrecy of your password, do not make files or directories sharable, pick up your printouts promptly and dispose of printouts where they will not tempt other students. All work should be done either in the class directory of your ITD account (preferred) or in your "priv" directory (only if you do not have a class directory).

All submissions should include a comment statement near the top of the program of the form:

THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING A TUTOR OR CODE WRITTEN BY OTHER STUDENTS - your name

Cases of apparent plagiarism or collusion will be referred to the Honor Council.