

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


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
4
4
x y z
Result
4
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
4
4
x y z
Overflow Result
4