CS 355 - Computer Organization/Architecture II
Project 2

Due: See class webpage.

### 0. Project Preparation

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

 ``` mkdir ~/cs355/pj2 cp /home/cs355001/Handouts/pj2/* ~/cs355/pj2 ```

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; You can use the Full_Adder components in project pj2 help-pj2 - the main simulation program file It creates switches and probes to help you test the circuit (macro) that you must make in this project pj2.h - This file contains the circuit that you must make for project 2 ```

### 1. Project Description

Write a ``Mult4'' component (i.e., a macro) that defines a 4-bit multiply circuit.

 A 4-bit multiply circuit performs a multiplication operation on two 4-bit binary (input) numbers and produce the result (= product) as a 8 bit binary (output) number

This component ``Mult4'' must be store in the file pj2.h so that it can be included by the help-pj2 circuit file provided for this project.

 ``` /* Skeleton program file for pj2 */ Define Mult4 x3 x2 x1 x0 y3 y2 y1 y0 | m7 m6 m5 m4 m3 m2 m1 m0; /* ------------------------------------------------------------ Write the multiply circuit here The 1st binary number = (x3 x2 x1 x0) - x0 is the least significant bit The 2nd binary number = (y3 y2 y1 y0) - y0 is the least significant bit The output (product) = (m7 m6 m5 m4 m3 m2 m1 m0) - m0 is the least significant bit ------------------------------------------------------------ */ Endef; ```

where:

 x3 x2 x1 x0 are the bits in the first 4 bit input operand. y3 y2 y1 y0 are the bits in the second 4 bit input operand. m7 m6 m5 m4 m3 m2 m1 m0 are the 7 bit output (which must be equal to the product of the 2 input numbers).

Defining a macro in EDiSim:

 I have discussed how to define a macros in class You can find more information on how to define macros (user-defined components) here: click here.

• Dictactical note:

 E.g.: In project 2, you need to define a macro. I have discussed the macro definition and use material in class prior to assigning this project. In case you missed the class above macros, study the material on this webpage: click here.

• To make this circuit, you will need:

 12 Full_Adder circuits and 16 AND gates (No other gates or components are necessary)

The Mult4 circuit has:

 two 4-bits inputs one 8-bits output

Schematically:

Example input and output of the multiplier circuit

### 2. Hint (we discussed this in class)

A multiplication of two 4-bit binary numbers can be broken up into 3 additions of 4-bit binary numbers. For example:
```                 1  0  1  1         multiplicant
x  1  0  0  1         multiplier
-----------------------
1  0  1  1         <--- 1
+         0  0  0  0            <--- 0
-----------------------
0  1  0  1  1
+      0  0  0  0               <--- 0
-----------------------
0  0  1  0  1  1
+   1  0  1  1                  <--- 1
-----------------------
1  1  0  0  0  1  1

```
Notice that:

 the sum is cascaded, i.e., a part of the result of the first sum is use as input for the second sum, and so on. the multiplier determines what to be added: when the multiplier bit is 1, the multiplicant is added and when the multiplier bit is 0, the value 0 is added.

### 3. Circuit test environment program file

• In this and all subsequent projects, I will provide you with one or more circuit test environment program files.

The circuit test environment program code will perform the following:

 Make the necessary input switches for a test circuit Make the necessary output probes for a test circuit Connect to the test circuit (that you have to create) I.e.: the "test environment" will make the necessary connections from the input switches and output probes to the test component circuit that you will make.

• Result:

 The circuit test environment program will create a test environment for a test component circuit (that you must create in the project) So that you don't have to bother making a circuit to test your project.

• With the help of my test environment for pj2 (which is the file help-pj2), all you have to do to complete the project is:

 Write the macro(s) that is used by the provided test circuit

• Example:

• The circuit test environment program file for pj2 is help-pj2 and its content is as follows:

 ``` #include "basic.h" #include "pj2.h" /* how help-pj2 obtains the Mult4 component definition */ /* Put up first input number */ Switch aa x3 '1' ZERO; Switch ab x2 '2' ZERO; Switch ac x1 '3' ZERO; Switch ad x0 '4' ZERO; /* Put up second input number */ Switch af y3 '6' ZERO; Switch ag y2 '7' ZERO; Switch ah y1 '8' ZERO; Switch ai y0 '9' ZERO; Mult4 cc-cf x3 x2 x1 x0 y3 y2 y1 y0 | m7 m6 m5 m4 m3 m2 m1 m0; /* Use the Mult4 component */ Probe eb m7; Probe ec m6; Probe ed m5; Probe ee m4; Probe ef m3; Probe eg m2; Probe eh m1; Probe ei m0; ```

To make this test circuit work, all you have to do is:

 Define (= write) the Mult4 macro inside the file pj2.h (which will be included into help-pj2 ) !!!!!!!!!!

### 4. The basic.h help file

• I have made some commonly used components and put them in the file name basic.h that you have copied into your project directory.

In this project, you will need to use some full adders to make the 4-bits multiply circuit

 ``` /* Full adder. Syntax: Full_Adder a b c_in | c_out s; Effect: Adds binary numbers a + b with carry. */ Define Full_Adder CarryIn a b | CarryOut Sum; Xor aa a b x; Xor ab x CarryIn Sum; And bb a b y; And cb CarryIn x z; Or cc y z CarryOut; Endef; ```

(Take a look inside the basic.h file in your project directory.

You can use the Full_Adder component that is defined in the help file basic.h in this project.

• To define (= create) a Full_Adder component, in your circuit, use this statement:

 ``` Full_Adder aa carryIn inp1 inp0 | carryOut sum ; ```

An example of how to use the Full_Adder component can be found in the demo program file 4-bit-adder which was demonstrated in class:

 ``` See: /home/cs355001/demo/circuits/4-bit-adder ```

### 5. The circuit project pj2.h skeleton program file

• To complete pj2, you must write the 4-bits multiply circuit as a macro in the skeleton program file pj2.h:

 ```/* Skeleton program file for pj2 */ Define Mult4 x3 x2 x1 x0 y3 y2 y1 y0 | m7 m6 m5 m4 m3 m2 m1 m0; /* ------------------------------------------------------------ Write the multiply circuit here ------------------------------------------------------------ */ Endef; ```

Use this skeleton program file and write a EDiSim macro that will multiply:

 A 4 bits input number x3 x2 x1 x0, and A 4 bits input number y3 y2 y1 y0

and outputs the product as a 8 bit number m7 m6 m5 m4 m3 m2 m1 m0

The least significant bit of the binary number has index 0 and the most significant bit of the binary number has index 3 or 7.

• To run this project, use this command:

 ``` cs355sim help-pj2 ```

Ofcourse, this command will only work after you have define the Mult4 component in the file pj2.h

• To see how the project 2 circuit should behave, use this command:

 ``` /home/cs355001/Solutions/pj2-sol ```

Summary and an important note:

• The files you need to do this project are:

 help-pj2: the circuit test environment program file (do not change this file !)              pj2.h: the skeleton project file --- where you write the circuit for the project (you only change this file !) basic.h: commonly used circuits in the CS355 project (do not change this file !) --- you will need to use Full_Adder defined in this file in pj2

• Make sure that the files:

 help-pj2              pj2.h basic.h

are stored in the same directory when you compile help-pj2 (because the help-pj2 needs these 2 files to compile and they are included from the current directory)

### 4. Turn in

• Turn in your pj2.h circuit file using the command:

 ``` /home/cs355001/turnin pj2.h pj2 ```

### 5. 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 pj2 ```

### 6. Handling Errors in EDiSim

I am compiling a list of commonly asked questions/answers on EDiSim projects.

I will keep updating this page when students report their compile and run time errors to me.

### 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.