Verilog刷题笔记2

题目:

Build a combinational circuit with four inputs, in[3:0]. There are 3
outputs: out_and: output of a 4-input AND gate. out_or: output of a
4-input OR gate. out_xor: output of a 4-input XOR gate. To review the
AND, OR, and XOR operators, see andgate, norgate, and xnorgate. See
also: Even wider gates.
Verilog刷题笔记2_第1张图片

我的解法:

module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
    assign out_and=in[3]&in[2]&in[1]&in[0];
    assign out_or=in[3]||in[2]||in[1]||in[0];
    assign out_xor=in[3]^in[2]^in[1]^in[0];

endmodule

结果正确:
Verilog刷题笔记2_第2张图片
学习解法:

module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
    assign out_and = & in;
    assign out_or  = | in;
    assign out_xor = ^ in;
 
endmodule

你可能感兴趣的:(笔记)