找出哪个寄存器包含最大数字的最佳方法是什么?
reg [7:0] A;
reg [7:0] B;
reg [7:0] C;
reg [7:0] D;
reg [7:0] M;
always @(posedge CLK) begin
M <= max(A,B,C,D);
end
答案 0 :(得分:0)
always @(posedge CLK)
begin
if(A > B && A > C && A > D)
begin
M <= A;
end
else if(B > A && B > C && B > D)
begin
M <= B;
end
else if(C > A && C > B && C > D)
begin
M <= C;
end
else if(D > A && D > B && D > C)
begin
M <= D;
end
//else
// there are two or more regs have the same value
end