CS 355 - Computer Organization/Architecture II
Project 3

Due: See Class Webpage.

### 1. Project Description

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

 a 16 bit ALU               a 16 bit Shifter

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

Recall:

 In the CS355 project, I have taken a ``learn as you need it'' approach. In each project, I may point you to some notes on logic-sim or new techniques that are explained in the logic-sim handout (e.g., user-defined components)

• Recall that:

 Just like in project 2, I will provide you with circuit test environment and skeleton project program files. The skeleton project program file can be found in Section 3 of this write up The circuit test environment program files can be found in Section 4 of this write up (there are 2 files for this project)

### 2. Project Assignment

• Write a C function called ALU16( ) that defines a 16-bit ALU.

 The ALU for the CS 355 project is different from the one demonstratred in class !!! So be careful not to be confused with the one I demonstrated in class !!!

The C function header should be like this:

 ``` void ALU16(const SD &coord, const Signal &a, const Signal &b, const Signal &c, // c[1] c[0] const Signal &s, const Signal &N, const Signal &Z) { Module( coord, "ALU-16", (a,b,c), (s,N,Z) ); ..... complete the ALU function here } ```

The input parameters are as follows:

• a = the first (16 bit) binary number
• b = the second (16 bit) binary number
• c = two bits control signals to select the ALU operation

Selection scheme:

 ``` c[1] c[0] Function ----------------------------------- 0 0 Add (s = a + b) 0 1 AND (s = a AND b bitwise and) 1 0 Select a (s = a) 1 1 Not a (s = not a) ```

The output parameters are as follows:

• s = 16 bit result of the selected operation
• N = the negative flag

 N=1 is result s is negative (i.e., the left-most bit is equal to 1), otherwise N=0.

• Z = the zero flag

 Z=1 is result s is equal to 0000000000000000 (i.e., the all bits are equal to 0), otherwise Z=0.

The function of 16-bit ALU is described in more detail in Section 5 of this handout.

• Comment:

 Use the help-ALU.cc (click here) circuit test environment program file to test your ALU component. Just like the CPU discussed in class, you should first write a One_Bit_ALU( ) component that do the specified computations given in Section 3 on 1-bit binary numbers. Then, use the One_Bit_ALU( ) component to build the ALU16( ) component.

NOTE:

 There is Decoder2x4( ) component in basic.h that you can use to implement the ALU There is FULL_Adder( ) component in basic.h that you can use to implement the ALU

• Write a C function called SHIFTER16( ) that implements a 16-bit shifter circuit. 16-bit ALU.

The C function header should be like this:

 ``` void SHIFTER16(const SD &coord, const Signal &a, const Signal &c, // c[1] c[0] const Signal &s) { Module( coord, "Shifter-16", (a,c), s ); } ```

The input parameters of the shifter circuit are as follows:

• a = the (16 bit) binary number
• c = two bits control signals to select the Shifter operation

Selection scheme:

 ``` c[1] c[0] Function ----------------------------------- 0 0 No shift 0 1 Shift right 1 bit position 1 0 Shift left 1 bit position 1 1 Not used (any output is OK) ```

The output parameters of the shifter circuit are as follows:

 s = 16 bit result of the selected shift operation

Comment:

The 16-bit shifter is described in Section 6 of this handout.

• Important:

 Both C functions (ALU16( ) and and SHIFTER16( )) must be store in the skeleton project file named "alu-shf.h" (provided at the end of this write up)

### 3. Skeleton project file alu-shf.h

• The skeleton project file for pj3 is: alu-shf.h

Right click on the link and save a copy in your project directory

• You must use the alu-shf.h file to implement the ALU16( ) and the SHIFTER16( ) components:

 ```/* =================================================================== Skeleton file for CS355 pj3: 16 bit ALU and shifter =================================================================== */ /* -------------------------------------------------------------------- ALU16( coord, a, b, c, s, N, Z) inputs: a = first (16 bit) binary number b = second (16 bit) binary number c = 2 constrol signals to select the ALU operation c[1] c[0] Function ----------------------------------- 0 0 Add (s = a + b) 0 1 AND (s = a AND b bitwise and) 1 0 Select a (s = a) 1 1 Not a (s = not a) outputs: s = 16 bit result of the selected operation N = the negative flag (N=1 is result s is negative) Z = the zero flag (Z=1 if the result s is equal to 0) -------------------------------------------------------------------- */ void ALU16(const SD &coord, const Signal &a, const Signal &b, const Signal &c, // c[1] c[0] const Signal &s, const Signal &N, const Signal &Z) { Module( coord, "ALU-16", (a,b,c), (s,N,Z) ); } /* -------------------------------------------------------------------- SHIFTER16( coord, a, c, s) inputs: a = the (16 bit) input binary number c = 2 constrol signals to select the ALU operation c[1] c[0] Function --------------------------------- 0 0 no shift (s == a) 0 1 shift right 1 bit position 1 0 shift left 1 bit position 1 1 not used (any output is OK) outputs: s = the shifted result -------------------------------------------------------------------- */ void SHIFTER16(const SD &coord, const Signal &a, const Signal &c, // c[1] c[0] const Signal &s) { Module( coord, "Shifter-16", (a,c), s ); } ```

because:

 The provided circuit test environment program files will include the file alu-shf.h

### 4. Circuit test environment files

• To help you test the components in pj3, I have provide you with 2 circuit test environment program files.

• The 2 circuit test environment program files for pj3 are here:

 The help-ALU.cc file contains a test circuit environment to test your ALU circuit.

To compile and test the ALU16( ) component:

 ``` cs355sim help-ALU (Compile) simex (Test) ```

To see how the ALU16( ) circuit should behave, use this command:

 ``` /home/cs355000/Solutions/pj3-ALU ```

 The help-SHIFT.cc file contains a test circuit environment to test your Shifter circuit.

To compile and test the SHIFTER16( ) component:

 ``` cs355sim help-SHIFT (Compile) simex (Test) ```

To see how the SHIFTER16( ) circuit should behave, use this command:

 ``` /home/cs355000/Solutions/pj3-SHIFT ```

Help files list

Here again is the list of help files used in this project:

• alu-shf.h: the skeleton project file.
• help-ALU.cc : the circuit test environment program file for the ALU16( ) component
• help-SHIFT.cc: the circuit test environment program file for the SHIFTER16( ) component.

### 5. The 16 Bit ALU

The 16 bit ALU's function is schematically represented in the following figure:

The inputs of the ALU circuit are:

• a15 a14 ... a0: the first input (binary) number for the ALU.
• b15 b14 ... b0: the second input (binary) number for the ALU.
• c1 c0: control signal with the following meaning:

 c1 c0 = 0 0: output of ALU is sum of the input numbers. c1 c0 = 0 1: output of ALU is AND function of the input numbers. c1 c0 = 1 0: output of ALU is equal to the first number. c1 c0 = 1 1: output of ALU is the inverse (not function) of first number.

The outputs of the ALU circuit are:

 s15 s14 ... s0: the result of the selected operation of the ALU. N: negative flag.   N has the same value as bit s15 of the result. Z: zero flag.  Z = 1 if all s15 s14 ... s0 bits are zero.

Refer to the lecture material on how to construct an ALU

### 6. The 16-bit Shifter circuit

The 16-bit shifter circuit is given in the following figure:

The inputs of the Shifter circuit are:

• a15 a14 ... a0: the input number that we want to shift.
• c1 c0: control signals for the 16 bit shifter circuit.

The meaning of these signals are as follows:

 c1 c0 = 0 0: no shift. c1 c0 = 0 1: shift one bit to right. c1 c0 = 1 0: shift one bit to left. c1 c0 = 1 1: not used (no function).

The outputs of the shifter circuit are:

 s15 s14 ... s0: the result of the selected operation of the shifter.

The shifter implements a logical shift operation, meaning that:

 a ZERO bit is always shifted into the open location. The bit that is shifted out will be lost.

I have used a multiplexor in class to construct a shifter circuit. You need to figure out how to enhance the design to add the no shift functionality to the shifter circuit.

The best way to build this 16 bit shifter circuit is to first build a `one-bit-shifter' circuit then use sixteen of this `one-bit-shifter' circuits to construct the 16 bit shifter circuit.

The `one-bit-shifter' circuit looks like this:

The 1-bit-shifter circuit has 3 input (bits), 2 control and 1 output signals.

The inputs of the 1-bit-shifter circuit are:

 L: the `left' input bit of the 1-bit-shifter. C: the `center' input bit of the 1-bit-shifter. R: the `right' input bit of the 1-bit-shifter. c1 c0: control signals for the 1-bit shifter.

The 1-bit-shifter circuit should do the following to realise its function:

 c1 c0 = 0 0: the output z is equal to the center input C (no shift). c1 c0 = 0 1: the output z is equal to the left input L (in order to shift right). c1 c0 = 1 0: thr output z is equal to the right input R (in order to shift left). c1 c0 = 1 1: not used (no function).

I will let you figure out how you can use 16 of these 1-bit-shifter circuits to construct a 16 bit shifter circuit.

### 7. New and old materials that you need to know to do the project

• Arrays of signals

 In this project, you will be using arrays of signals (This topic would have been discussed in class). You can find information of array of signals here: click here

 You have already used this feature in pj2 In case you need to find information on how to define and use user-defined components, the page is here: click here

• Components in basic.h

• The following components in basic.h can be helpful (and used) in this project:

 Full_Adder( ): a full adder circuit (that you have used in project 2) Decoder2x4( ): a 2-by-4 decoder circuit.

### 8. Turn in

Turn in your "alu-shf.h" file that contains the ALU16( ) and the SHIFTER16( ) components as assignment pj3 with the following command:

 ``` /home/cs355000/turnin alu-shf.h pj3 ```

### 9. 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 pj3 ```

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