Laboratory 9 and Homework 9
AU - Arithmetic Unit of the CPU
Laboratory 9
The CPU of a computer is generally divided into at least four components,
the control unit which performs the fetch/execute cycle, the bus
unit which controls access to the data and address bus, internal registers
for temporary storage, and the arithmetic/logic unit (ALU) that
performs arithmetic and logical operations. The following laboratory focuses
on the arithmetic unit (AU) described in the text Section 10.3 and illustrated
in Figure 10.12 of the text. The homework assignment is to design and implement
an AU. The AU will be tested by performing the arithmetic for a simple
calculator.
Full Adder
The text describes several one bit full adders including one based on two
half adders such as those implemented in Home Work 1.
A three bit full adder was implemented in Home Work 5.
See Figure 10.3 page 281 for details. Also described in the text is the
carry-ripple
adder (Figure 10.2) implemented by cascading the carry out bit of one
full adder to the carry in of the next. This method allows large adders
to be easily implemented but suffers from a linear increase in propagation
delay as the number of bits in the operands increase.
Arithmetic Unit
The text also describes in Section 10.3 the details of an arithmetic
unit based upon a full adder of n bits. The AU given is capable
of five arithmetic operations, add, subtract, add with carry, complement,
and increment. The AU has inputs of two operands, an operation code, and
a carry in bit. The output is the operation results that include flags
indicating whether the result is zero, the carry out, whether
overflow
occurred, and the sign of the result. The following lists the key
points of the AU.
Adder - As noted, the 8 bit adder can be implemented based upon
8 cascaded full bit adders. The text gives several designs in Figure 10.3
page 281.
Multiplexer - The design given in the text requires an 8 input
multiplexer to select inputs to the adder. You may use one provided in
the MAX+plus II environment. The COMPONENT definition is:
COMPONENT a_2x8mux
PORT ( sel : IN BIT;
a, b : IN BIT_VECTOR(7 DOWNTO 0);
y : OUT BIT_VECTOR(7 DOWNTO 0));
END COMPONENT;
zero - The zero bit can be determined by taking the NOR of
all bits of the result, z in the text example. A bitwise NOT result most
easily done by first ORing all bits then NOT the result. Note that the
expression must be fully parenthenized to be evaluated correctly.
overflow - The ovf bit is determined by forming the XOR
of the carry out of the two most significant bits, bit 6 and
7.
sign - The sign bit is the most significant bit of the
result.
Operations - The AU can perform 5 operations that are encoded
as 3 bit codes in Table 10.4 page 298 of the text. For example, the operation
code 001 instructs the AU to add, with the effect z = x + y. Different
operations are implemented by decoding the operation code into three control
signals, Kx, Ky, and Kmx.
-
Kx and Ky - Purpose is to form the one's complement of x
and
y
respectively
when 1.
-
Kmx - Selects whether the second adder operand is y or 0.
Unary operations such as increment use 0 for the second operand.
-
Computing Kx, Ky, Kmx - Ky and Kmx are bits 1 and
0 of the operation code respectively. Kx is bit 2 of the
operation
code
except for code 101, when Kx is 0 rather than 1. As stated in the
text, these can be computed from the operation code by:
-
Kx = bit 2 * bit 1
-
Ky = bit 1
-
Kmx = bit 0
Homework 9
Assignment .
-
Implement an 8 bit full adder based upon the carry-ripple adder of
Home
Work 5.
-
Implement an 8 bit AU as described in the text in Section 10.3.
-
Test using the provided HW9 component and the HyperTerminal program
that implement a simple calculator.
Files
There are several files needed for fully testing and debugging the
AU component. These files are in a self-expanding file which can be downloaded
by clicking HW9.exe.
Turn In
-
Cover Page - Your name, date, and Homework 9. Staple all
pages together.
-
Simulation of the 8 bit adder component adding 00000001 + 01111111, and
00000010 + 11111111.
-
VHDL listing of the 8 bit adder component.
-
Simulation of the AU component performing 00000001 + 01111111, 11111111
+ 00000010, and 00000001 - 00000010.
-
VHDL listing of the AU component.
-
Demonstrate calculator (HW9 component) to instructor.
AU Design
-
Follow the design of the text in Section 10.3.
-
Use the operation codes as defined in Table 10.4 page 198.
Implementation
Points of note:
-
Use the FLEX FPGA.
-
The interface must agree exactly with that given in the test component
HW9.
Use the ENTITY name of AU for your component. The ENTITY must appear
as:
PORT(
opCode : IN BIT_VECTOR(2 DOWNTO 0);
cin : IN BIT;
x, y : IN BIT_VECTOR(7 DOWNTO 0);
z : OUT BIT_VECTOR(7 DOWNTO 0);
cout, zero, sgn, ovf
: OUT BIT);
END COMPONENT;
-
The clock rate of the HW9 component must not exceed the propagation
time of the AU component.
Testing
The testing component, HW9, implements a very, very simple calculator.
Operands and operations are entered from the computer keyboard and results
are displayed back to the display. To keep the UP1 design simple and continue
to use the HyperTerm program on the PC for data input and output, the calculator
interface is very crude. To enter a calculation to add 65 + 3 enter:
-
A
The character corresponding to ASCII code 65 decimal or 41 hexadecimal.
-
!
Character for addition, its ASCII code is 00100001, the low three bits
are 001, the AU code for +.
-
Ctrl D Character code 4.
-
Any key The character 'E' should be displayed to the HyperTerminal
screen.
-
Any key And hexadecimal code 45 for 'E' displayed on the LEDs.
As each character is entered, the LEDs display the hexadecimal value for
the operand or operation entered. Pressing the FLEX_PB1 push button will
display the present state of the main FSM. The states are:
0 - Read first operand.
1 - Read operation and display first operand to LED .
2 - Read second operand or any key if only one operand required (e.g.
complement), and display operation to LED.
3 - Display AU result to computer screen.
4 - Read any key stroke and display second operand to LED.
5 - Read any key stroke and display AU result to LED.
Debugging
It is essential that each component, adder and AU, be thoroughly debugged
before attempting to test on the UP1. Once the adder and AU component operation
has been verified through simulation, the following debugging steps are
appropriate with the UP1 connected to the PC serial port.
-
Do arithmetic on obvious characters, for example, '9'-4 is '5'. That could
be entered as:
-
9
-
#
-
Ctrl D
Ascii code 4
-
Any key
-
Any key
-
Use the LED display to examine the operations, operand, result, and state.
See the note above on testing for information on the LED output.
-
Try slowing down the HW9 clock in case that it is too fast for a carry-ripple
adder. Do not slow it below 2*4800 Hz. since the serial I/O is running
at 4800 Hz. and the HW9 must run at least twice that to ensure that it
doesn't miss serial input signals when characters arrive.
-
Use the LED output to read back the operands, operation, and result. From
the character printed to the screen, it may not be obvious what its numerical
value should be.
Arithmetic Unit Component
Test
The following tests the AU by reading two operands and an arithmetic
operator from the computer keyboard and displaying the result as a
character back to the display. The operands, operator, and result are also
displayed on the two 7-segment LEDs. As in Home Work
8, the serial input and output is provided using the Windows 95 terminal
program named HyperTerminal. To test the AU component do the following
steps:
-
Make a new directory and copy all the VHDL files of the components used
by your AU.vhd component.
-
A test component, HW9, implements the calculator on the UP1 using
your AU. Download the self expanding file HW9.exewhich
contains the calcuator components.
-
Run HW9.exe file, by default it will create a HW9 directory
containing all the files except the AU.vhd.
-
Copy your AU.vhd component to the directory containing HW9
files.
-
Open HW9.vhd file, click
to set the current project, compile the HW9.vhd component. Ignore
the warnings about: Project has user pin assignments but has never been
compiled before.
-
Programming the FPGA requires:
-
Connect the ByteBlaster cable to the parallel port of the
computer and the UP1 JAG IN.
-
Connect the power plug to the UP1 DC IN.
-
Check that the four programming jumpers located above the MAX FPGA are
correctly positioned for the FLEX FPGA. TD1 and TD0 jumpers should both
be on the bottom, DEVICE and BOARD jumpers should be on the top. See UP1
EQUIPMENT FAMILIARIZATION for a graphic.
-
Use menu Max+plus II, Programmer menu or click on
.
-
Use menu JTAG, check Multi-Device JTAG Chain.
-
Use menu JTAG, and Multi-Device JTAG Chain Setup....You
should see a window similar to below.

-
Click
to
remove any previously used files from programmer list.
-
Click
to
list available programming files.
-
Select the HW9.sof file and click
to add it to the Device Names. Click OK.
-
Click in the Programmer window as below and then click Configure.
The
Program
box should show programming progress and indicate when programming of the
FPGA is completed.
-
To communicate with the UP1 over the serial cable.

-
The UP1 and computer serial ports must be connected. Connect the mini-DIN
connector
to the UP1 (the mini-DIN is the small, round connector) and cable to the
DB 9 pin serial port connector (top DB 9 pin connector is Com1, bottom
is COM2) on the back of the PC. See UP1
EQUIPMENT FAMILIARIZATION for a graphic.
-
Run the
program
from the Program/Accessories/HyperTerminal folder. Give it a name
to call the new connection.
-
You should see a window similar to the one at right. Select a connection
Direct
to COM 1.
-
The next window is Port Settings, select Bits per Second
as 4800 to match the clock rate of the HW9 component.
Document last modified: