Professional Documents
Culture Documents
Group members:
ARSLAN JAVAID
CMS # 27189
Project title:
Designing an 8-Bit Arithmetic Logic Unit Using ModelSim
ABSTRACT:
By increasing the demand of enhancing the ability of processors to handle the more complex and
challenging processors has resulted in the integration of a number of processor cores into one chip. Still
the load of on the processor is not less in generic system. An Arithmetic Logic Unit (ALU) is the heart of
all microprocessors. It is a combinational logic unit that performs its logical or arithmetic operations.
ALU is getting smaller and more complex nowadays to enable the development of a more powerful but
smaller computer.
In this project an 8-bit Arithmetic Logic Unit (ALU) is designed and implemented in ModelSim SE-64
10.5 using Verilog Programming language. It includes writing, compiling and simulating Verilog code in
ModelSim 10.5 on a Windows 8.1 platform.
Introduction:
Arithmetic Logical Unit (ALU)
It is a critical component of the microprocessor and core component of central processing unit. ALU
comprises the combinational logic that implements logic operations such as AND and OR, and arithmetic
operations such as Addition, Subtraction, and Multiplication.
In digital electronics, an arithmetic logic unit (ALU) is a digital circuit that performs arithmetic and bit-
wise logical operations on integer binary numbers. It is a fundamental building block of the central
processing unit (CPU) found in many computers and microcontrollers.
Inputs to an ALU are the data to be operated on (called operands) and a code indicating the operation to
be performed, while the ALU’s output is the result of the performed operation. In many designs, the ALU
also exchanges additional information with a status register, which relates to the result of current or
previous operations. The pin diagram of the ALU is shown in Fig. 1 and its description in Table I.
Fig 1 ALU Pin Diagram
to the left or right, with or without sign extension). Shifts can be seen as
In 8 bit ALU there are two 8 bit operands A (7:0) and B (7:0) and result is stored in S (7:0).
The ALU function table with opcodes, instructions and operations performed are listed in Table II.
Table II: ALU FUNCTIONS
Opcode Instruction Operation
ARITHMETIC
UNIT
0000 A+B Addition
0001 A-B Subtraction
0010 A*B Multiplication
0011 A/B Division
0100 A<<1 Logical shift left
0101 A>>1 Logical shift right
0110 {A[6:0],A[7]} Rotate left
0111 {A[0],A[7:1]} Rotate right
LOGIC UNIT
1000 A&B Logical and
1001 A|B Logical or
1010 A^B Logical xor
1011 ~(A | B) Logical nor
1100 ~(A & B) Logical nand
1101 ~(A ^ B) Logical xnor
1110 (A>B)?8'd1:8'd0 Greater comparison
1111 (A==B)?8'd1:8'd0 Equal comparison
8-bit ALU Implementation in Verilog on ModelSim
1. First, install ModelSim on a Windows PC.
2. Double click ModelSim SE-64 10.5 icon from the desktop.
3. Dialogue box named “important information “will appear .Close this dialogue box as shown in
figure below:
4. Go to file option then change directory option and set working directory as shown in figure:
5. Go to file ..new..source…Verilog as shown in figure below:
);
always @(*)
begin
case(ALU_Sel)
4'b0000: // Addition
ALU_Result = A + B ;
4'b0001: // Subtraction
ALU_Result = A - B ;
4'b0010: // Multiplication
ALU_Result = A * B;
4'b0011: // Division
ALU_Result = A/B;
ALU_Result = A<<1;
ALU_Result = A>>1;
ALU_Result = {A[6:0],A[7]};
ALU_Result = {A[0],A[7:1]};
ALU_Result = A & B;
4'b1001: // Logical or
ALU_Result = A | B;
ALU_Result = A ^ B;
ALU_Result = (A>B)?8'd1:8'd0 ;
ALU_Result = (A==B)?8'd1:8'd0 ;
default: ALU_Result = A + B ;
endcase
end
endmodule
module tb_alu;
//Inputs
reg[7:0] A,B;
reg[3:0] ALU_Sel;
//Outputs
wire[7:0] ALU_Out;
wire CarryOut;
integer i;
alu test_unit(
);
initial
begin
A = 8'h0A;
// B = 4'h02;
B = 8'h02;
// ALU_Sel = 4'h0;
ALU_Sel = 4'b0000;
#100
for (i=0;i<=15;i=i+1)
begin
//#10
#10;
end
A = 8'hF6;
B = 8'h0A;
end
endmodule
2. Another window of simulation will appear. Click “Add wave” as shown in figure to observe the
waveforms results.
3. Run simulation from run button as shown in figure
4. Results of the waveforms of outputs of ALU based on input select lines is shown below:
Timing diagram
Conclusion
This project helps to understand how to implement 8-bit ALU in ModelSim using Verilog. After writing
ALU code, test bench was written to verify the functionality of ALU. On running simulation it was verified
that ALU is successfully built.