Question

In: Physics

write an Arithmetic Logic Unit (ALU) in verilog.

write an Arithmetic Logic Unit (ALU) in verilog.

Solutions

Expert Solution

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

module ALU(

A,

B,

Op,

R );

input [7:0] A,B;

input [2:0] Op;

output [7:0] R;

wire [7:0] Reg1,Reg2;

reg [7:0] Reg3;

assign Reg1 = A;

assign Reg2 = B;

assign R = Reg3;

always @(Op or Reg1 or Reg2)

begin

case (Op)

0 : Reg3 = Reg1 + Reg2; //addition

1 : Reg3 = Reg1 - Reg2; //subtraction

2 : Reg3 = ~Reg1; //NOT gate

3 : Reg3 = ~(Reg1 & Reg2); //NAND gate

4 : Reg3 = ~(Reg1 | Reg2); //NOR gate

5 : Reg3 = Reg1 & Reg2; //AND gate

6 : Reg3 = Reg1 | Reg2; //OR gate

7 : Reg3 = Reg1 ^ Reg2; //XOR gate

endcase

end

endmodule

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

`timescale 1ns / 1ps

////////////////////////////////////////////////////////////////////////////////

module tb_alu;

// Inputs

reg [7:0] A;

reg [7:0] B;

reg [2:0] Op;

// Outputs

wire [7:0] R;

// Instantiate the Unit Under Test (UUT)

ALU uut (

.A(A),

.B(B),

.Op(Op),

.R(R)

);

initial begin

// Apply inputs.

A = 8'b01101010;

B = 8'b00111011;

Op = 0; #100;

Op = 1; #100;

Op = 2; #100;

Op = 3; #100;

Op = 4; #100;

Op = 5; #100;

Op = 6; #100;

Op = 7; #100;

end

endmodule


Related Solutions

Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
Write the VERILOG code for an arithmetic/logic unit (ALU) following , and can be tested in...
Write the VERILOG code for an arithmetic/logic unit (ALU) following , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B; ---------------------------------------------------------------------- | 0011 | ALU_Out = A / B; ---------------------------------------------------------------------- |...
The heart of a computer system is an ARITHMETIC AND LOGIC UNIT (ALU) which is responsible...
The heart of a computer system is an ARITHMETIC AND LOGIC UNIT (ALU) which is responsible for executing arithmetic (e.g., addition, subtraction, etc.) and logic (e.g., AND, OR, etc.) operations. In this project, you will design, simulate, and implement a simple 1-bit ALU. The truth table for ALU is given below: Operation Selection Inputs Operation Output(s) S0 S1 A B 0 0 A AND B AB 0 1 A NOR B (A+B)’ 1 0 A XNOR B (A⊕B)’ 1 1...
draw state machine and write verilog code of an ALU unit that shifts left when the...
draw state machine and write verilog code of an ALU unit that shifts left when the control signal 'OP' is 00, shifts right when control is ''01'' and increments when control is ''10''. Fpr control ''11'' , it does nothing. inputs are Date [3:0] and clk, and the output is Out [3:0]
use modelsim write Verilog code for the following digital logic circuits and then simulate them by...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by writing a testbench module for each of them , (a)The FSMs for the snail problem that is in the slides (a snail crawls over a tape that has 0 and 1 and smiles if it has detected the '10' bits using both Moore and Mealy FSM. Note that the pattern is '10' not '01' as in the slides. (b) A rock-paper-scissor game played by...
1. a) Given the two Verilog code segments, derive the schematics for the logic that will...
1. a) Given the two Verilog code segments, derive the schematics for the logic that will be synthesized from these blocks. BLOCK 1 input Y; reg A, B; always @(posedge clk) begin A = Y; B = A; end BLOCK 2 input Y; reg A, B; always @(posedge clk) begin A <= Y; B <= A; end b) Define setup time by using timing diagrams. Explain what would happen if any one of these timing requirements are violated. c) Describe...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries. Only this libraries are allowed to use: use library ieee; use ieee.std_logic_1164.all; Please do it correctly and include the comments for me to fully understand. Thank you.
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed...
Write VHDL code for ALU 32bit. ALU must perform addition and subtraction. You are not allowed to use other libraries only this is allowed to use library ieee; use ieee.std_logic_1164.all; Please write the comments for me to fully understand. Thank you.
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT