In: Physics
write an Arithmetic Logic Unit (ALU) in verilog.
An Arithmetic Logic Unit (ALU) performs Arithmetic operations on input numbers like Addition, Subtraction, Division, Multiplication, & digital Gates operations like AND, OR, NOT, or any other operation you want.
Here, we will be using sequential approach for designing ALU in verilog. We will input numbers from user and will apply “CASE” statement on operation. On the base of user choice, the required operation will be performed and result will be displayed to the user.
Verilog Code For Arithmetic Logic Unit (ALU)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Verilog Code Explanation
We have taken “R” as output & A,B as input. Since we are using sequential approach, we define register R3 of same dimension. Our program will execute if any of input or “Operation” will change. We have applied Case statement on “OP” so the proper operation will be selected through Case statements.
You can add as many operations as you want. The testbench for above code is given below. You can change test bench values or change time interval. This has been tested on Xilinx ISE.
TestBench For ALU
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|