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/cs355000/Handouts/pj2/* ~/cs355/pj2

You will copy these files:

 basic.h - the commonly used circuit components in the CS355 projects pj2-main.cc - the main simulation program file It creates switches and probes to help you test the circuit that you must make in the project pj2.h - This file contains the circuit that you must make for project 2

### 1. Project Description

Write a ``Multiply4'' component (i.e., a C-function) 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 ``Multiply4'' must be store in the file pj2.h so that it can be included by a help file provided for this project.

The ``Multiply4'' component header should be like this:

 void Multiply4( const SD &coord, const Signal &x, const Signal &y, const Signal &m) { Module( coord, "Multiple", (x,y), m); .... }

where:

 x[3..0] is the first 4 bit input operand. y[3..0] is the second 4 bit input operand. m[7..0] is the 7 bit output (which is the product of the 2 input numbers).

• Dictactical note:

 I would already have discussed the relevant Logic-sim material in class In case you missed the class, I have linked the material in this project page --- such as the link click here above

• To make this circuit, you will need:

 12 full-adder circuits and 16 AND gates (No other gates or components are necessary)

The Multiply4 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 Make the test circuit (that you have to create) Make the necessary connection from the input switches and output probes to the test component circuit

• In other words:

 The circuit test environment program will create a test environment for a test component circuit (that you must create in the project)

• What you must do to complete the project is:

 Write the C-function that defines the test component circuit

• Example:

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

 #include "Sim.h" #include "basic.h" // Includes some basic components that I made #include "pj2.h" // Includes the test component definition void simnet() { Sig(x, 4); // defines signals x[3] x[2] x[1] x[0] Sig(y, 4); // defines signals y[3] y[2] y[1] y[0] Sig(m, 8); // defines signals m[7] m[6] ... m[1] m[0] /* Put up first input number */ Switch("aa", x[3], '0', Zero); // Switches for the first number Switch("ab", x[2], '1', Zero); Switch("ac", x[1], '2', Zero); Switch("ad", x[0], '3', Zero); /* Put up second input number */ Switch("af", y[3], '4', Zero); // Switches for the second number Switch("ag", y[2], '5', Zero); Switch("ah", y[1], '6', Zero); Switch("ai", y[0], '7', Zero); Multiply4("cc-cf", x, y, m); // The test component circuit ProbeH( "eb-ei", m); // Probe the outputs }

### 4. The basic.h help file

• I have made some commonly used components and put them in the file name basic.h

In this project, you will need to use full adders for this project.

 void Full_Adder( const SD &coord, const Signal &a, const Signal &b, const Signal &CarryIn, const Signal &Sum, const Signal &CarryOut) { Module( coord, "FA", (CarryIn,a,b), (CarryOut,Sum) ); Signal x, y, z; Xor( SD(coord,"aa"), (a,b), x); Xor( SD(coord,"ab"), (x, CarryIn), Sum); And( SD(coord,"bb"), (a, b), y); And( SD(coord,"cb"), (CarryIn, x), z); Or ( SD(coord,"bc-cc"), (y, z), CarryOut); }

You can use the Full_Adder component that is defined in the help file basic.h in your pj2.

• You must first save a copy of basic.h into your project directory to use the components defined in basic.h:

 Right Click on the hyper link and save a copy in your cs355 project directory.

(Read more on how to define and use components by clicking on here .)

• After saving the basic.h file in your porject directory, your logic-sim programs can make use of the components defined inside basic.h

In order to make the basic.h components available to your pj2 logic-sim program that you will be writing, you need to include the basic.h file into your pj2 C-program with this C-preprocessor directive:

 #include "basic.h"

This directive will read in (= "include") the file "basic.h" into your C-program.

Because the "basic.h" file contains the Full_Adder definition, the C compiler will recognize the Full_Adder function when you use it in your C-program.

Important note:

• I have already put the #include command in the circuit test environment program file (described above) that you will be using to do pj2.

• Therefore, you do not need to use the #include "basic.h" command in your pj2.h file (because I have already included baisc.h in the circuit test environment program file pj2-main.cc )

 I am only explaining the #include command here so you know exactly what is going on

• To define (i.e., make a real) a Full_Adder component, use this statement:

 Full_Adder( "xy", a-bit, b-bit, carry-in-bit, sum-bit, carry-out-bit);

An example of its use can be found in the demo program file 4-bit-adder.cc which was demonstrated in class:

 void simnet() { Signal x0, x1, x2, x3, y0, y1, y2, y3; // Two 4-bit numbers Sig(c, 4); // Carry outputs of the full adders Sig(s, 4); // Sum bit outputs of the full adders Switch("aa", x3, '0', Zero); Switch("ab", x2, '1', Zero); Switch("ac", x1, '2', Zero); Switch("ad", x0, '3', Zero); Switch("af", y3, '4', Zero); Switch("ag", y2, '5', Zero); Switch("ah", y1, '6', Zero); Switch("ai", y0, '7', Zero); Full_Adder("cb", x3, y3, c[2], s[3], c[3]); // How to use Full_Adder component Full_Adder("cd", x2, y2, c[1], s[2], c[2]); Full_Adder("cf", x1, y1, c[0], s[1], c[1]); Full_Adder("ch", x0, y0, Zero, s[0], c[0]); /* ====================================== Probe the outputs ====================================== */ Probe("eb", c[3]); // Carry Probe("ed", s[3]); Probe("ee", s[2]); Probe("ef", s[1]); Probe("eg", s[0]); }

As you can see, the Full_Adder behaves like an ordinary logic-sim component.

Please don't forget the coordinate parameter !!!

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

The file contains the Multiple4 C function:

 void Multiply4( const SD &coord, const Signal &x, const Signal &y, const Signal &m) { Module( coord, "Multiple", (x,y), m); /* ====================================================== Write the multiply circuit here.... When you're done, compile with: cs355sim pj2-main And run it with: simex ====================================================== */ }

Use this skeleton program file and write a logic-sim component that will multiply:

 A 4 bit input number x, and A 4 bit input number y

and outputs the product as a 8 bit number m

• To compile this project, use this command:

 cs355sim pj2-main

• To run the project, use this command:

 simex

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

• Note:

• You can see that pj2-main.cc includes the file pj2.h and the basic.h component file:

 #include "Sim.h" #include "basic.h" // Include it so you can access my provided components #include "pj2.h" // YOU must write this program

So when you compile your circuit test environment program file pj2-main.cc, it will include your project file pj2.h.

• Furthermore, pj2-main.cc included basic.h (containing the Full_Adder definition) before it includes pj2.h.

So the function(s) inside pj2.h can use any component that is defined inside basic.h when you write the Multiply4 component in pj2.h

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

 /home/cs355000/Solutions/pj2-sol

• Summary and an important note:

• The files you need to do this project are:

 pj2-main.cc: 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 !)

• Make sure that the files:

 pj2-main.cc              pj2.h basic.h

are stored in the same directory when you compile pj2-main.cc (because the pj2-main.cc 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/cs355000/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/cs355000/req-ext pj2

### 6. Handling Errors in Logic-Sim

I am compiling a list of commonly asked questions/answers on logic-sim 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.