ALU (20 pts) Implement a 32-bit ALU. Input: a (32 bits), b (32 bits), and op (3 bits). Output: s (32 bits). The ALU shou
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
ALU (20 pts) Implement a 32-bit ALU. Input: a (32 bits), b (32 bits), and op (3 bits). Output: s (32 bits). The ALU shou
module ALU(input [31:0] a,
input [31:0] b,
input [2:0] op,
output reg [31:0] s);
//write your code here
always @(*) begin
case (op)
0:s=a+b;
1:s=a-b;
2:s=a+1;
3:s=0;
4:s=a&b;
5:s=a|b;
6:s=a^b;
7:s=~a;
default: s=0;
endcase
end
endmodule
here is my code.
but I have no idea to write the TestBench code,
can some explain how to write the TestBench code for me pls!
ALU (20 pts) Implement a 32-bit ALU. Input: a (32 bits), b (32 bits), and op (3 bits). Output: s (32 bits). The ALU should send the results of operations with a and b to s. The operations are specified by the value of op, as shown in the following table: Assume a = 0x0000001 and b = OxFFFFFFFF, we Table 3: Operations of ALU op operation 0 a + b 1 a - b 2 a + 1 3 0 4 a AND 5 a OR b 6 a XOR b 7 NOT a S Ox00000000 Ox00000002 Ox00000002 Ox00000000 Ox00000001 OxFFFFFFFF OxFFFFFFFE OxFFFFFFF also show the results of each operations in the above table. Notice that AND, OR, XOR, and NOT are bitwise operations. Evaluation Your score will be computed out of a maximum 100 points. 80 points are given based on the correctness of all modules. 20 points are given based on your testbench code.