Project Report Arithmetic Logic Unit (ALU)
Project Report Arithmetic Logic Unit (ALU)
ALU
(ARITHMETIC &
LOCICAL
UNIT)
BY
NARESH SINGH DOBAL
9540493245
nsdobal@gmail.com
1.
INTRODUCTION
TO
VHDL
Introduction
to
model
digital
system
at
many
levels
of
=> VHDL
as
waveforms
an
can
interconnection
also
be
of
generated
components.
using
the
Test
same
1.1
descriptions,
algorithmic
descriptions
and
1.2
Entity declaration
specifies
the
name
of
the
entity
being
Figure: AND_GATE
Behavioral
Defines a sequentially described functioning of the design.
Structural
Defines a interconnections between previously defined
components.
Dataflow
A combination of structural and behavioral architectures .
The
different
modeling
styles
explained below
A.
are
body
is
composed
of
two
parts:
the
instantiation
statements.
U1,
U2,
and
U1
are
the
assignment
assignment
statements
statements).
In
(or
a
sequential
signal
signal
assignment
C.
begin
appearing
and
within
end
the
process).
statement
The
part
statements
are
executed
sequential
Sequential
variable
signal
signal
assignment
assignment
assignment
statements.
statements,
statements,
are
including
executed
D.
statements
their
order
and
of
concurrent
appearance
statements;
within
the
within
executed sequentially.
process
statement
art
always
the
configuration
for
an
entity-architecture
is
created.
An
example
of
the
configuration
1.2.4 Package--
Package body:
This provides the implementation details of sub programs,
Items declared in the body are not visible to the user of
the package.
1.2.5
Test bench
test
bench
allows
the
designer
to
verify
the
instantiates
the
design
under
test
(DUT).
It
HIGH LEVEL
DESIGN FLOW
For
-- XILINX -Software
tools
The high level design flow is illustrated in figure.
tool.
The
tool
reports
syntax
errors
and
2.3
RTL Simulation--
In
Simulation,
RTL
the
designer
uses
stimulus
that
2.4
2.5 Implementation
Implementation (Place and route) tools are used to take
the design netlist and implement the design in the target
technology device. The place and route tools place each
primitive from the netlist into an appropriate location on
target
device
and
then
route
signals
between
the
identified
during
the
static
timing
analysis
cells are, the shorter the routed signals will be and the
shorter the time delay.
Some place and route tools allow the designer to
specify the placement of large parts of the design. This
process is also known as floor planning. Floor planning
allows the user to pick locations on the chip for large
blocks of the design so that routing wires are as short as
possible. The designer lays out blocks on the chip as
general areas. The floor planner feeds this information to
the place and route tools so that these blocks are placed
properly. After the cells are placed, the router makes the
appropriate connections.
After all the cells are place and routed, the output of
the place and route tools consists of data files that can be
used to implement the chip. In the case of FPGAs, these
files describe all of the connections needed to fuse FPGAs
macrocells to implement the functionality required. Antifuse FPGAs use this information to burn the appropriate
fuses
while
reprogrammable
devices
download
this
This
file
describes
the
actual
timing
of
the
process.
There
are
number
of
methods
to
simulations
this
requires
VITAL
compliant
3.
DESIGNING
STEPS
1.
3.
5.
6.
7.
8.
9.
ARCHITECTURE CODING
INTRODUCTION
To
ARITHMETIC
LOGIC
UNIT
(ALU)
The Arithmetic Logic Unit (ALU) is essentially the heart of a CPU. This is what
allows the computer to add, subtract, and to perform basic logical operations such
as AND/OR. Since every computer needs to be able to do these simple functions,
they are always included in a CPU. How a company designs their ALU has a
significant impact on the overall performance of their CPU. In this article I will
give a brief introduction to some basics of ALU design; you will quickly see how
complicated these things can get.
instruction word) that contains an operation code (sometimes called an "op code"),
one or more operands, and sometimes a format code. The operation code tells the
ALU what operation to perform and the operands are used in the operation. (For
example, two operands might be added together or compared logically.) The
format may be combined with the op code and tells, for example, whether this is a
fixed-point or a floating-point instruction. The output consists of a result that is
placed in a storage register and settings that indicate whether the operation was
performed successfully. (If it isn't, some sort of status will be stored in a permanent
place that is sometimes called the machine status word.)
In general, the ALU includes storage places for input operands, operands that are
being added, the accumulated result (stored in an accumulator), and shifted results.
The flow of bits and the operations performed on them in the subunits of the ALU
is controlled by gated circuits. The gates in these circuits are controlled by a
sequence logic unit that uses a particular algorithm or sequence for each operation
code. In the arithmetic unit, multiplication and division are done by a series of
adding or subtracting and shifting operations. There are several ways to represent
negative numbers. In the logic unit, one of 16 possible logic operations can be
performed - such as comparing two operands and identifying where bits don't
match.
The design of the ALU is obviously a critical part of the processor and new
approaches to speeding up instruction handling are continually being developed.
In computing, an arithmetic logic unit (ALU) is a digital circuit that performs
arithmetic and logical operations. The ALU is a fundamental building block of the
central processing unit (CPU) of a computer, and even the simplest
microprocessors contain one for purposes such as maintaining timers. The
processors found inside modern CPUs and graphics processing units (GPUs)
accommodate very powerful and very complex ALUs; a single component may
contain a number of ALUs.
control
system
unit
and
maintains
directs
the
order
flow
within
of
traffic
statement
at
time
from
impulses
to
the
appropriate
does
the
not
data.
one
perform
the
Specifically,
control
stop
(control
and
timing),
what
to
do
(program
or
interfacing
with
by
the arithmetic-logic
design
of
capability
the computer,
to
function
the
CPU
under
can
manual
also
have
control
the
through
areas. These
logically
defined
areas
the
decision-
An interrupt
information)
for
random-access
storage
given
memory
Control
(RAM) consisting of
is
small,
UNIT The
and
test
arithmetic-logic
operations
division)
various
and
(addition,
logic
conditions
unit
(ALU)
subtraction,
operations. Logic
encountered
during
logical functions are inputs from the designated CPU registers and
operands. The
operations.
circuits
and
ALU
relies
These
on
include
number
(adders/subtracters),
registers. Figure
diagram
of
an
1-2
ALU
basic
shows
a
to
systems,
timing,
of
items
perform
data
its
routing
instructions, operands,
a representative
microcomputer.
block
PRIMARY
the
intermediate
operations.
storage
This
section.
is
It
a
is
results
working
of
the
storage
arithmetic-logic
area within
the
output
Registers
(IR, PC, ACC)
Control Unit
(CU)
Arithmetic Logic Unit
(ALU)
ARITHMETIC LOGIC UNIT STRUCTURES
An ALU must process numbers using the same format as the rest of the digital
circuit. The format of modern processors is almost always the two's complement
binary number representation. Early computers used a wide variety of number
systems, including one's complement, sign-magnitude format, and even true
decimal systems, with ten tubes per digit.
ALUs for each one of these numeric systems had different designs, and that
influenced the current preference for two's complement, as this is the
representation that makes it easier for the ALUs to calculate additions and
subtractions.
The two's-complement number system allows for subtraction to be accomplished
by adding the negative of a number in a very simple way which negates the need
for specialized circuits to do subtraction.
practical overview
Most of a processor's operations are performed by one or more ALUs. An ALU
loads data from input registers, an external Control Unit then tells the ALU what
operation to perform on that data, and then the ALU stores its result into an output
register. Other mechanisms move data between these registers and memory.
Simple operation
A simple example arithmetic logic unit (2-bit ALU) that does AND, OR, XOR, and
addition
Most ALUs can perform the following operations:
Complex operations
Engineers can design an Arithmetic Logic Unit to calculate any operation. The
more complex the operation, the more expensive the ALU is, the more space it
uses in the processor, the more power it dissipates. Therefore, engineers
compromise. They make the ALU powerful enough to make the processor fast, but
yet not so complex as to become prohibitive. For example, computing the square
root of a number might use :
1. Calculation in a single clock Design an extraordinarily complex ALU that
calculates the square root of any number in a single step.
2. Calculation pipeline Design a very complex ALU that calculates the square
root of any number in several steps. The intermediate results go through a
series of circuits arranged like a factory production line. The ALU can
accept new numbers to calculate even before having finished the previous
ones. The ALU can now produce numbers as fast as a single-clock ALU,
although the results start to flow out of the ALU only after an initial delay.
The inputs to the ALU are the data to be operated on (called operands) and a code
from the control unit indicating which operation to perform. Its output is the result
of the computation.
In many designs the ALU also takes or generates as inputs or outputs a set of
condition codes from or to a status register. These codes are used to indicate cases
such as carry-in or carry-out, overflow, divide-by-zero, etc.
ALUs vs. FPUs
A Floating Point Unit also performs arithmetic operations between two values, but
they do so for numbers in floating point representation, which is much more
complicated than the two's complement representation used in a typical ALU. In
order to do these calculations, a FPU has several complex circuits built-in,
including some internal ALUs.
In modern practice, engineers typically refer to the ALU as the circuit that
performs integer arithmetic operations (like two's complement and BCD). Circuits
that calculate more complex formats like floating point, complex numbers, etc.
usually receive a more specific name such as FPU.
Logic Gates
Before we get to the overall design of an ALU, we first have to understand the
basics of logic gates. Figure 1 shows the basic logic gates shown in their graphical
representations. Keep in mind that each of these can be made from transistors by
combining them in different ways. What types of transistors and how they are
arranged can impact the performance of the gate.
'AND' Gate
'OR' Gate
'XOR' Gate
'NOT' Gate
'NAND' Gate
'NOR' Gate
'XNOR' Gate
(or a low voltage), if one or both inputs are false. Likewise, if we consider the 'OR'
gate the output will be true if input #1 or input #2 are true. The 'XOR' gate output
will be true if either input is true, but false if both inputs are true; this is an
implementation of the exclusive 'OR' logic operation. The 'NOT' gate will output
the opposite of the input; so if the input is true the 'NOT' gate's output will be false.
The 'NAND', 'NOR', and 'XNOR' gates are implementations of the 'AND', 'OR',
and 'XOR' gates respectively with a 'NOT' gate prior to the output; so a 'NAND'
gate will return what a 'AND' gate does not.
These logic functions are by themselves an important part of a CPU's functionality,
but performing logic operations on two inputs is only so useful. By combining
these gates together we can have devices with more inputs. For example, in Figure
2 I have combined three 'AND' gates. These three 'AND' gates will produce an
output that is true only when all four inputs are true. In essence, this is a 4 bit
'AND' gate. You can extrapolate from this and form an 8 bit 'AND' gate by
combining two 4 bit 'AND's and one 2 bit 'AND'.
Arithmetic
By combining these gates into even more clever configurations we can perform
other useful functions, like addition. Figure 3 shows a typical configuration
referred to as a half-adder. To understand how this adder works we have to think of
the inputs not as true or false but as '1' or '0'. The output of this adder is the sum of
the inputs with a carry bit. If the inputs are '1' and '1' we are adding 1 plus 1. The
output labeled 'SUM' is just an 'XOR' of the inputs which will be '0'. The output
labeled 'CARRY' is an AND gate which of course will be '1'. The addition answer
therefore is 10 which is the binary addition of '1' and '1'. If the inputs are '1' and '0'
the 'SUM' will be '1' and the 'CARRY' will be '0', giving an answer of 01 or just 1.
Figure 3: A half-adder
So, if this is performing binary addition why is it called a half-adder? This is
because in order to add binary numbers greater than two bits we need the adder to
be able to take in a carry bit along with the two input bits. This full-adder is shown
in Figure 4. You can see that the full-adder is two half-adders with one additional
'OR' gate. To use a full-adder to add two binary numbers of arbitrary size you will
begin with the right most bit, called the least significant bit (LSB) of each number
with a carry in bit of '0'. You would then add the two bits, record the sum, and use
the carry out bit as the carry in bit when adding the next two bits and moving
towards the most significant bits (MSB). By repeating this process you can add
two binary numbers of any arbitrary length. This process is known as a ripple
carry.
Figure 4: A full-adder
Figure 5 shows a half-sub. In this scenario if we have input 'A' equal to '1' and
input 'B' equal to '0' we want to subtract 0 from 1. You can see that the 'DIFF'
output will be '1' and the 'BORROW' Output will be '0'. Like the half-adder, the
half-sub can be used to implement a full-sub, shown in Figure 6.
Figure 5: A half-sub
Figure 6: A full-sub
Arithmetic units are usually grouped together into an ALU which has inputs,
outputs, and control bits which tell the ALU which type of operation to perform.
Figure 7 shows a typical diagram of an ALU. In this diagram A and B are the data
inputs, F is the control input to choose the function, R is the result of the function
applied to A and B, and D is the status of the output so that you know when the
function is done.
The example of the ripple carry addition is an effective method of adding binary
numbers. Let us extrapolate this a little bit and imagine a 32-bit adder. If we want
to add two 32-bit numbers we can start at the LSB and move left as we calculate
the carry bits. If adding two bits takes a couple of clock cycles, then the total time
taken to add all 32 bits is significant. Thankfully this problem has already been
solved. The solution: a carry look ahead adder.
In a carry look ahead adder the binary numbers are split into sections, perhaps of 4
bits each. Now each section can begin calculating its carry bits beginning with the
section's LSB and moving towards the section's MSB. Once a carry bit reaches the
MSB of its section the bit can then jump ahead 4-bits at a time instead of
continuing towards the number's MSB one bit at a time. The logic involved with
keeping all of the carries straight is quite complex and becomes more complex as
the size of the sections increase; because of this more time is spent calculating the
carries of each section and less time on the faster propagation of the carry bits.
However, if the section size is too small then there are so many sections for the
carries to propagate through that there is not much time saved versus the ripple
carry adder. Deciding upon a section size involves a detailed analysis of the gate
and propagation delays which can vary depending on the technology used within
the logic gates.
The carry look ahead technique is one optimization the engineers can make to the
ALU. There are many others. For instance, to do multiplication one would
normally just add the number to itself over and over, but there are optimization
techniques that can be employed to speed this process up. These are some of the
differences between the ALUs of various processors and a major reason why some
processors are better at certain types of operations than others. For instance, a GPU
will have an ALU which is optimized for the arithmetic often performed for the
display of graphics while a CPU will have an ALU designed to be optimized for
the most common operations performed by users.
PROGRAM
FOR ALU
IN VHDL--
--------------------------------------------------------------------------------- Title
: alu
-- Design
-- Author
: NARESH DOBAL
-- Company
: NSD
---------------------------------------------------------------------------------- File
: alu.vhd
---------------------------------------------------------------------------------- Description :
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity alu is
port(
din1 : in STD_LOGIC_VECTOR(3 downto 0);
din2 : in STD_LOGIC_VECTOR(3 downto 0);
sel : in STD_LOGIC_VECTOR(3 downto 0);
dout : out STD_LOGIC_VECTOR(3 downto 0)
);
end alu;
begin
with sel select
dout <= din1 and din2 when "0000",
end alu_arc;
OUTPUT
WAVE-FORM
OF ALU
CIRCUIT DIAGRAM
FOR ABOVE CODE
GENERATED BY
SYNTHESIS TOOL
(RTL LAYOUT DESIGN)