题解 | #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

#刷题#
全部评论

相关推荐

10-13 16:58
门头沟学院 Java
面了100年面试不知...:一周七天,一天去一家上班😍😍😍
点赞 评论 收藏
分享
况世奇才:我七月投的Java,面试官说搞大数据的,挂个Java的吸引进来投简历的,已经offer评估了看看能不能泡出来吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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