Computer Architecture Project: Ministry of Education Taif University College of Computers & Information Technology
Computer Architecture Project: Ministry of Education Taif University College of Computers & Information Technology
Ministry of Education
Taif University
College of Computers & Information Technology
Contents
1 Introduction 2
2 Project Objective 2
3 Design Stages 2
3.1 Requirement Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 Functional Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.3 High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.4 Detailed Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.4.1 Arithmetic Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.4.2 Logic Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.4.3 Shift Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.4.4 Output Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Implementation 5
5 Testing 6
6 Conclusion 6
Page 1 of 6
Taif University - Computer Architecture Project: 8-bit ALU Design
1 Introduction
This project presents the design and implementation of an 8-bit Arithmetic Logic Unit
(ALU) for the Computer Architecture course (503323-3) at Taif University. The ALU
is a critical component of a CPU, capable of performing arithmetic, logic, and shift op-
erations. The design is organized into stages, including requirement analysis, functional
specification, high-level and detailed design, implementation in Verilog HDL, and test-
ing. The solution adheres to the project requirements, ensuring all 14 operations are
implemented and documented.
2 Project Objective
The objective is to design an 8-bit ALU that performs:
The operations are selected using five control inputs (S3 , S2 , S1 , S0 , Cin ), as specified in
the function table.
3 Design Stages
3.1 Requirement Analysis
• Inputs:
Page 2 of 6
Taif University - Computer Architecture Project: 8-bit ALU Design
Page 3 of 6
Taif University - Computer Architecture Project: 8-bit ALU Design
• Operations:
– Addition: F = A + B.
– Addition with carry: F = A + B + Cin .
– Subtraction: F = A + B + 1.
– Subtraction with borrow: F = A + B.
– Increment: F = A + 1.
– Decrement: F = A − 1.
– Transfer: F = A.
• Control Logic:
– AND: F = A ∧ B.
– OR: F = A ∨ B.
– XOR: F = A ⊕ B.
– NOT: F = A.
Page 4 of 6
Taif University - Computer Architecture Project: 8-bit ALU Design
4 Implementation
The ALU is implemented in Verilog HDL. The code is provided below:
1 module alu_8bit (
2 input [7:0] A , B , // 8 - bit operands
3 input [3:0] S , // Selection inputs S3 , S2 , S1 , S0
4 input Cin , // Carry - in
5 output reg [7:0] F // 8 - bit result
6 );
7 wire [7:0] arith_out , logic_out , shift_out ;
8 wire [7:0] B_mod ;
9 wire Cin_mod ;
10
11 // Arithmetic Unit
12 assign B_mod = ( S [1:0] == 2 ’ b01 ) ? ~ B : //
Subtraction : NOT B
13 ( S [1:0] == 2 ’ b10 && ! Cin ) ? 8 ’ hFF : //
Decrement : -1
14 8 ’ h00 ; //
Increment / Transfer : 0
15 assign Cin_mod = ( S [1:0] == 2 ’ b00 ) ? Cin : //
Addition : use Cin
16 ( S [1:0] == 2 ’ b01 ) ? ~ Cin : //
Subtraction : invert Cin
17 ( S [1:0] == 2 ’ b10 && Cin ) ? 1 : //
Transfer : Cin =1
18 ( S [1:0] == 2 ’ b11 ) ? 1 : //
Increment : +1
19 0; //
Decrement : -1
20 assign arith_out = A + B_mod + Cin_mod ;
21
22 // Logic Unit
23 wire [7:0] and_out = A & B ;
24 wire [7:0] or_out = A | B ;
25 wire [7:0] xor_out = A ^ B ;
26 wire [7:0] not_out = ~ A ;
27 assign logic_out = ( S [1:0] == 2 ’ b00 ) ? and_out :
28 ( S [1:0] == 2 ’ b01 ) ? or_out :
29 ( S [1:0] == 2 ’ b10 ) ? xor_out :
30 not_out ;
Page 5 of 6
Taif University - Computer Architecture Project: 8-bit ALU Design
31
32 // Shift Unit
33 assign shift_out = ( S [1] == 0) ? {1 ’ b0 , A [7:1]} : // Shift
Right
34 { A [6:0] , 1 ’ b0 }; // Shift
Left
35
36 // Output Multiplexer
37 always @ (*) begin
38 case ( S [3:2])
39 2 ’ b00 : F = arith_out ; // Arithmetic operations
40 2 ’ b01 : F = logic_out ; // Logic operations
41 2 ’ b10 : F = shift_out ; // Shift operations
42 default : F = 8 ’ h00 ; // Undefined
43 endcase
44 end
45 endmodule
5 Testing
The ALU design is verified through simulation with the following test cases:
Simulation tools like ModelSim or Vivado can be used. A Verilog testbench can automate
testing of all operations.
6 Conclusion
The 8-bit ALU design successfully implements all 14 required operations using a modular
architecture with arithmetic, logic, and shift units. The Verilog implementation is efficient
and verifiable. The design meets the project requirements and is presented in a well-
organizeddocument.
Page 6 of 6