题解 | #全加器#

全加器

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

`timescale 1ns/1ns

module add_half(

   input                A   ,

   input                B   ,

 

   output   wire        S   ,

   output   wire        C   

);

assign S = A ^ B;

assign C = A & B;

endmodule

/***************************************************************/

module add_full(

   input                A   ,

   input                B   ,

   input                Ci  , 

   output   wire        S   ,

   output   wire        Co   

);

wire S0;//半加器A+B的输出

wire C0;

add_half AB_add(

    .A(A),

    .B(B),

    .S(S0),

    .C(C0)

);

wire C1;//半加器S0+Ci的输出

add_half S0Ci_add(

    .A(S0),

    .B(Ci),

    .S(S),

    .C(C1)

);

assign Co = C0|C1;

endmodule

/*

A B     S0  Ci   S  C1  C0  Co

0 0     0    0    0   0   0   0

0 1     1    0    1   0   0   0

1 0     1    0    0   1   0   1

1 1     0    1    1   0   1   1

*/

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务