Question

2. In this question, you are asked to design a synthesizable ALU in Verilog. This ALU...

2. In this question, you are asked to design a synthesizable ALU in Verilog. This ALU gets two 9-bit signed inputs (A, B) in 2’s complement format, and a 4-bit select input (S) based on which decides about the operation that should be executed. The output is Q, and you determine the number of bits for Q in order to have a correct answer. What follows shows these operations:

If S=0 Addition (i.e., A+B)

If S=1 Subtraction (A-B)

If S=2 Multiplication (only the least 8 significant bits are shown in output)

If S=3 Shift B to the right A times (and add 0 from right side)

If S=4 Rotate B to the left A times

If S=5 A is ored with B

If S=6 A is anded with B

If S=7 A is nanded with B

If S=8 A is xnored (the logical opposite of XOR, like NAND to AND) with B

If S=9 complement of B is computed

I am confuse here how to addition, subtraction and multiplication

my attempt so far

module ALU(A, B , S, Q);
input [9:0] A;
input [9:0] B;
input [4:0] S;
output reg Q;

always @* begin
case (S)
5'b00000 : Q = A[9:0] + A[9:0] ;
5'b00001 : Q = 0 ;
5'b00010 : Q =
5'b00011 : Q =
5'b00100 : Q = A | B ;
5'b00101 : Q = A & B ;
5'b00110 : Q = A ~&B ;
5'b00111 : Q = A B ;
5'b01000 : Q = A
5'b01001 :
endcase

end
endmodule

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// please look for the mistakes u made with the bit vector numbering and also with the output logic

module alu(a,b,out,sel);
input signed [8:0] a,b;// inputs 9 bits each signed
input signed [3:0] sel;// 4 bit select signal signed
output reg signed [8:0] out;// since alu is 8 bit hence output should be 8 bits wide
  
always@(*)
begin
case(sel)
0: out=a+b;
1: out=a-b;
2: out=a*b;
3: out=b>>a;
4: out=b<<a;
5: out=a|b;
6: out=a&b;
7: out=a ~& b;
8: out=a ~^ b;
9:out=~b;
default:out=0;
endcase
end
endmodule

Add a comment
Know the answer?
Add Answer to:
2. In this question, you are asked to design a synthesizable ALU in Verilog. This ALU...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The assignment is build an 8 bit ALU in structural verilog NOT behavioral : Requirements are to design the ALU to implement NAND, AND, OR, NOT, XOR, XNOR, ADD, SUBTRACT, COMPARE, etc. WIll be executed...

    The assignment is build an 8 bit ALU in structural verilog NOT behavioral : Requirements are to design the ALU to implement NAND, AND, OR, NOT, XOR, XNOR, ADD, SUBTRACT, COMPARE, etc. WIll be executed on 2s complemented throughout. 15 Op codes necessary are the following: -Transfer A -Increment A -Addition -Subtraction -Decrement A -1s comp -A and B,A NAND B,A or B, A NOR B, A XOR B, A XNOR B, -A greater than B -A Les than B...

  • Write an Verilog code for a 8-bit subtractor (Bits are in 1's complement) using the following:...

    Write an Verilog code for a 8-bit subtractor (Bits are in 1's complement) using the following: 1. 5-bit parallel adder 2. 3-bit parallel adder The condition are as follows: 1. The Most Significant bits of the subtractor must be given to the 5-bit parallel adder. 2, The Least Significant bits of the subtractor must be given to the 3-bit parallel adder. 3. The input A will be assign to the switches with the least significant bit A[0] linked to SW0....

  • Q2. Design a 8-bit ALU (Arithmetic Logic Unit) supporting the following instructions, Z and C values...

    Q2. Design a 8-bit ALU (Arithmetic Logic Unit) supporting the following instructions, Z and C values should be re-evaluated (updated) ifY changes Instruction type code[2:0] operations Logical Status update 001 010 011 100 101 110 ( Bitwise AND) Y = A & B: | Z (C is always 0) (bitwise OR) Y- A B; (bitwise XOR) Y-A B Z (Cis always 0) (negation) Y =-A; (Addition) Y A + B: (subtraction) Y = A-B: (Increment) Y-A+1 (decrement) Y-A-1 Z (C...

  • VHDL structural code please Design an 8-bit add/subtract in Verilog AND VHDL using any of the...

    VHDL structural code please Design an 8-bit add/subtract in Verilog AND VHDL using any of the coding styles and language features covered so far in modules 8 and 9. When AS Sel0 it performs an addition, else when AS Sel 1 it performs a subtraction. OpA and OpB are assumed to be signed, 2's-Complement numbers. Hint: Bit-wise XOR AS Sel with OpB before adding it to OpA- see lecture notes Op87.0Add/ Subtract Vout

  • Question: Part 1: In the second part of this lab, we will extend our adder to...

    Question: Part 1: In the second part of this lab, we will extend our adder to also allow for subtraction of the second number from the first. To implement this, we must take the 2's compliment of the second number and add it to the first. This can be implemented using the circuit shown in Section 4.4.2 of the notes, which is shown again here in Figure 2. B3 A3 B2 A B, A, B, A, -SM 0: Add 1:...

  • PROBLEM STATEMENT The mini-calculator will use a small ALU to perform arithmetic operations on two 4-bit values which are set using switches. The ALU operations described below are implemented with a...

    PROBLEM STATEMENT The mini-calculator will use a small ALU to perform arithmetic operations on two 4-bit values which are set using switches. The ALU operations described below are implemented with an Adder/Subtractor component. A pushbutton input allows the current arithmetic result to be saved. An upgraded mini-calculator allows the saved value to be used in place of B as one of the operands. The small ALU that you will design will use the 4-bit adder myadder4 to do several possible...

  • The Arithmetic Logic Unit The first topic for the project is to create an Arithmetic Logic...

    The Arithmetic Logic Unit The first topic for the project is to create an Arithmetic Logic Unit, using a structured approached with a Virtual Hardware Design Language such as Verilog. Mainly, the program is very close to a simulator for a programming calculator. An ALU typically has the following operations Math Functions: Add, Subtract, Multiply, Divide, Modulus Logic Functions: And, Or, XOR, Not, Nand, Nor, XNOR Error Modes: Divide by Zero, Overflow Support Functions: No Operation, Shift Left, Shift Right,...

  • DIGITAL DESIGN ​​​​​​​ Q3 Derive the functional block diagram (fbd) that is described by the Verilog...

    DIGITAL DESIGN ​​​​​​​ Q3 Derive the functional block diagram (fbd) that is described by the Verilog code in Listing Q3 module Q3(a, b, m, n, z); input [1:0] a, b; input m, n; output reg (0:3]z; reg (1:0) w; always@ (a, b, m) if (m== 1) w=a & b; else w=ab; always@ (w, n) if(n==0) z=0; else case(w) 2'600: z= 4'h8; 2'601: z= 4'h4; 2'b10: z= 4'h2; 2'b11: z=4'hl; endcase endmodule Listing Q3 (10 marks)

  • Please code the following in Verilog: Write the HDL gate-level hierarchical description of a four-bit adder-subtractor...

    Please code the following in Verilog: Write the HDL gate-level hierarchical description of a four-bit adder-subtractor for unsigned binary numbers similar to the following circuit. You can instantiate the four-bit full adder described in the following example code Figure 4.13a, 4-Bit adder-subtractor without overflow Inputs: 4-Bit A, 4-Bit B, and Mode M (0-add/1-subtract) Interfaces: Carry Bits C1, C2, C3 Outputs: Carry C (1 Bit, C4), Sum S (4 bit) Bo A FA FA FA FA module Add half (input a,...

  • Using Structural Modeling in VHDL write the code for: An Arithmetic Logic Unit (ALU) shown in...

    Using Structural Modeling in VHDL write the code for: An Arithmetic Logic Unit (ALU) shown in the figure below. A (16-bit), B (16-bit), Opcode (3-bit), and Mode (1-bit) are the inputs; and ALUOut (16-bit) and Cout (1-bit) are the outputs of the design. A and B hold the values of the operands. Mode and Opcode together indicate the type of the operation performed by ALU. The ALU components ARE: -Arithmetic Unit that consists of one 16-bit adder, 16-bit subtractor, 16-bit...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT