Docsity

ECE 474a/574a Programming Project 1: Implementing a 4-bit ALU - Prof. Susan Lysecky, Study Guides, Projects, Research of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 474a/574a - Programming Project 1 (20 points)
Due February 1, 2008 (Friday) at 8:00 pm
Deliverables (one submission per group, be sure to include both group member names)
• Verilog code implementing structural ALU
• Verilog code implementing behavioral ALU
• Verilog testbench verifying functionality of both ALU implementations
Turnin
• Submit your project using electronic turnin, class_account_name is “ece474a”, assignment_name is “proj1”
Project Description
In this project you will implement a 4-bit ALU using a structural and behavioral methodology. The structural implementation
should consist only of primitives or module definitions using primitives, with the ALU described as a hierarchical
interconnection those modules/primitives. Hint: an ALU is composed of muxes and an adder. Your code should likewise have
mux module(s), an adder module, and perhaps other components if needed. Then the ALU module simply instantiates and
connects these components together.
In the behavioral implementation the ALU specification should consist of arithmetic expressions, procedural assignments, or
other Verilog control flow structures. Hint: in this implementation you only need the ALU module.
The ALU has two 4-bit inputs, A and B, with values specified in the two’s complement format. Additionally, there are three
1-bit inputs x, y, and z which specify the operation performed by the ALU. The resulting value is outputted as a 4-bit value
called Result. The ALU block diagram and ALU operation table is specified below.
Please make sure to declare your module as shown in the example below to help the grader test your module. For the
structural ALU implementation replace “_beh” with “_struct”.
// Behavioral ALU specification
module ALU_beh(A, B, x, y, z, Result);
input [3:0] A, B;
input x, y, z;
output [3:0] Result;
Additionally, you will need to create a Testbench to check the functionality of your ALU. You should be able to use the same
testbench to test both ALU implementations. Be sure to test enough scenarios to be confident in your implementation.
Inputs
x y z Operation
0 0 0 Result = A
0 0 1 Result = A + 1
0 1 0 Result = A + B
0 1 1 Result = A – B
1 0 0 Result = A AND B
1 0 1 Result = A OR B
1 1 0 Result = A >> 1
1 1 1 Result = A << 2
4-bit ALU
A
4
B
4
x
y
z
Result
4
…
pf2

Partial preview of the text

Download ECE 474a/574a Programming Project 1: Implementing a 4-bit ALU - Prof. Susan Lysecky and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

ECE 474a/574a - Programming Project 1 (20 points)

Due February 1, 2008 (Friday) at 8:00 pm

Deliverables (one submission per group, be sure to include both group member names)

  • Verilog code implementing structural ALU
  • Verilog code implementing behavioral ALU
  • Verilog testbench verifying functionality of both ALU implementations

Turnin

  • Submit your project using electronic turnin, class_account_name is “ece474a”, assignment_name is “proj1”

Project Description

In this project you will implement a 4-bit ALU using a structural and behavioral methodology. The structural implementation should consist only of primitives or module definitions using primitives, with the ALU described as a hierarchical interconnection those modules/primitives. Hint: an ALU is composed of muxes and an adder. Your code should likewise have mux module(s), an adder module, and perhaps other components if needed. Then the ALU module simply instantiates and connects these components together.

In the behavioral implementation the ALU specification should consist of arithmetic expressions, procedural assignments, or other Verilog control flow structures. Hint: in this implementation you only need the ALU module.

The ALU has two 4-bit inputs, A and B , with values specified in the two’s complement format. Additionally, there are three 1-bit inputs x , y , and z which specify the operation performed by the ALU. The resulting value is outputted as a 4-bit value called Result. The ALU block diagram and ALU operation table is specified below.

Please make sure to declare your module as shown in the example below to help the grader test your module. For the structural ALU implementation replace “ _beh ” with “ _struct ”.

// Behavioral ALU specification module ALU_beh(A, B, x, y, z, Result); input [3:0] A, B; input x, y, z; output [3:0] Result;

Additionally, you will need to create a Testbench to check the functionality of your ALU. You should be able to use the same testbench to test both ALU implementations. Be sure to test enough scenarios to be confident in your implementation.

Inputs x y z Operation 0 0 0 Result = A 0 0 1 Result = A + 1 0 1 0 Result = A + B 0 1 1 Result = A – B 1 0 0 Result = A AND B 1 0 1 Result = A OR B 1 1 0 Result = A >> 1 1 1 1 Result = A << 2

4-bit ALU

A

4

B

4

x y z

Result

4

ECE 574 A ONLY

Add an extra 1-bit output called Overflow to the ALU to detect when overflow occurs. Set Overflow = 1 when the result is not correct due to an overflow scenario. Otherwise Overflow = 0. Note that the overflow bit is not necessary for all operations (i.e. no overflow in AND operation), you may decide what to set the Overflow bit to when this flag is not used.

Again, please declare your behavioral ALU module as shown in the example below to help the grader interface to your module. For the structural ALU implementation replace “ _beh ” with “ _struct ”.

// Behavioral ALU specification module ALU_beh (A, B, x, y, z, overflow, Result); input [3:0] A, B; input x, y, z; output [3:0] Result; output overflow; 4-bit ALU

A

4

B

4

x y z

Overflow Result

4