题解 | #4位数值比较器电路#

4位数值比较器电路

https://www.nowcoder.com/practice/e02fde10f1914527b6b6871b97aef86d

`timescale 1ns/1ns
 
module comparator_4(
    input       [3:0]       A       ,
    input      [3:0]        B       ,
  
    output   wire       Y2    , //A>B
    output   wire        Y1    , //A=B
    output   wire        Y0      //A<B
);
 
wire [2:0] y0;
wire [2:0] y1;
wire [2:0] y2;
wire [2:0] y3;
//Y0=P(A<B)=P(A3<B3)+P(A3=B3)P(A2<B2)+P(A3=B3)P(A2=B2)P(A1<B1)+P(A3=B3)P(A2=B2)P(A1=B1)P(A0<B0)
//Y1=P(A=B)=P(A3=B3)P(A2=B2)P(A1=B1)P(A0=B0)
//Y2=P(A>B)=P(A3>B3)+P(A3=B3)P(A2>B2)+P(A3=B3)P(A2=B2)P(A1>B1)+P(A3=B3)P(A2=B2)P(A1=B1)P(A0>B0)
function [2:0] comparator_1;
    input A;
    input B;
    begin
    comparator_1[0] = (!A)&B;
    comparator_1[1] = (A&B)|((!A)&(!B));
    comparator_1[2] = A&(!B);
    end
endfunction
assign y0 = comparator_1(A[0],B[0]);
assign y1 = comparator_1(A[1],B[1]);
assign y2 = comparator_1(A[2],B[2]);
assign y3 = comparator_1(A[3],B[3]);
 
assign Y0 = y3[0]|(y3[1]&y2[0])|(y3[1]&y2[1]&y1[0])|(y3[1]&y2[1]&y1[1]&y0[0]);
assign Y1 = y3[1]&y2[1]&y1[1]&y0[1];
assign Y2 = y3[2]|(y3[1]&y2[2])|(y3[1]&y2[1]&y1[2])|(y3[1]&y2[1]&y1[1]&y0[2]);
 
endmodule

#刷题#
全部评论

相关推荐

asdasdasdasdas:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
昨天 17:07
沈阳大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务