我正在完成一项任务,有点迷茫,不知道如何开始。我需要在 32 位 ALU 中实现以下标志:
• Z(“Zero”):如果运算结果为零,则设置为 1(“True”)
• N(“Negative”):如果结果的第一位是 1,则设置为 1(“True”),表示负数
• O(“溢出”):设置为1(“真”)表示操作溢出总线宽度。
此外,一个比较函数将输入 a 与输入 b 进行比较,然后设置三个标志之一:
• 如果输入 a 小于输入 b,则为 LT
• GT 如果输入 a 大于输入 b
• EQ 如果输入 a 等于输入 b
我需要修改此 ALU 以包含三个标志和比较输出,然后更改测试台以测试所有这些修改。
这是我为这项作业收到的所有信息,实际上没有教科书或任何其他资源。这是一个在线课程,我无法得到老师的回应。所以我对如何开始有点困惑。在数字逻辑方面,我仍然是个新手,所以请多多包涵。我只需要一些帮助来理解这些标志和比较是如何工作的。如果有人能更好地向我解释它们是如何工作的,它们是做什么的,以及我如何将它们实现到 ALU 和测试平台中,我将不胜感激。
我不指望任何人来完成我的任务,我真的只需要帮助理解它。
铝型材
module alu32 (a, b, out, sel);
input [31:0] a, b;
input [3:0] sel;
output [31:0] out,
reg [31:0] out;
//Code starts here
always @(a, b, sel)
begin
case (sel)
//Arithmetic Functions
0 : out <= a + b;
1 : out <= a - b;
2 : out <= b - a;
3 : out <= a * b;
4 : out <= a / b;
5 : out <= b % a;
//Bit-wise Logic Functions
6 : out <= ~a; //Not
7 : out <= a & b; //And
8 : out <= a | b; //Or
9 : out <= a ^ b; //XOR
10 : out <= a ^~ b; //XNOR
//Logic Functions
11 : out <= !a;
12 : out <= a && b;
13 : out <= a || b;
default: out <= a + b;
endcase
end
endmodule
ALU 测试台
module alu32_tb();
reg [31:0] a, b;
reg [3:0] sel;
wire [31:0] out;
initial begin
$monitor("sel=%d a=%d b=%d out=%d", sel,a,b,out);
//Fundamental tests - all a+b
#0 sel=4'd0; a = 8'd0; b = 8'd0;
#1 sel=4'd0; a = 8'd0; b = 8'd25;
#1 sel=4'd0; a = 8'd37; b = 8'd0;
#1 sel=4'd0; a = 8'd45; b = 8'd75;
//Arithmetic
#1 sel=4'd1; a = 8'd120; b = 8'd25; //a-b
#1 sel=4'd2; a = 8'd30; b = 8'd120; //b-a
#1 sel=4'd3; a = 8'd75; b = 8'd3; //a*b
#1 sel=4'd4; a = 8'd75; b = 8'd3; //a/b
#1 sel=4'd5; a = 8'd74; b = 8'd3; //a%b
//Bit-wise Logic Functions
#1 sel=4'd6; a = 8'd31; //Not
#1 sel=4'd7; a = 8'd31; b = 8'd31; //And
#1 sel=4'd8; a = 8'd30; b = 8'd1; //Or
#1 sel=4'd9; a = 8'd30; b = 8'd1; //XOR
#1 sel=4'd10; a = 8'd30; b = 8'd1; //XNOR
//Logic Functions
#1 sel=4'd11; a = 8'd25; //Not
#1 sel=4'd12; a = 8'd30; b = 8'd0; //And
#1 sel=4'd13; a = 8'd0; b = 8'd30; //Or
#1 $finish;
end
alu32 myalu (.a(a), .b(b), .out(out), .sel(sel));
endmodule