Combinational Logic Circuits Verilog
Combinational Logic Circuits Verilog
Combinational circuits use logic gates to perform operations such as addition, comparison, and selection.
The output depends only on the current input values. Examples include multiplexers, decoders, adders, and simple
logical functions.
input a, b;
output c, d, e;
assign d = a | b; // OR gate
endmodule
Explanation: The 'assign' statement is used for continuous assignment to create simple gates.
3. Multiplexer (MUX)
A MUX selects one of several input signals based on select lines and forwards it to the output.
output reg f;
2'b00: f = w0;
2'b01: f = w1;
2'b10: f = w2;
2'b11: f = w3;
default: f = 0;
endcase
end
endmodule
Explanation: The 'case' statement selects the input based on the value of 's'.
4. Decoder
if (en) begin
endcase
end else
end
endmodule
Explanation: The 'case' statement decodes the input and activates the corresponding output.
5. Full Adder
A full adder adds two single-bit numbers and a carry-in, producing a sum and a carry-out.
Verilog Code:
input a, b, cin;
endmodule
Explanation: The full adder uses 'assign' statements to compute the sum and carry-out.
6. Priority Encoder
A priority encoder outputs the binary representation of the highest-priority active input.
valid = 1;
casez (in) // 'z' allows don't-care conditions
default: begin
out = 2'b00;
end
endcase
end
endmodule
Explanation: The 'casez' statement handles priority encoding, with '?' as a wildcard.