1. 문제 및 설명
- a와 b 중 하나를 선택하는 2:1 mux를 만들어라. 단, sel_b1과 sel_b2가 모두 참일 때 b를 선택하고, 그렇지 않으면 a를 선택한다.
- 이 mux를 assign 문을 사용하는 방식과 procedural if 문을 사용하는 방식 두 가지로 각각 구현하라.

2. 모듈 정의
module top_module(
input a,
input b,
input sel_b1,
input sel_b2,
output wire out_assign,
output reg out_always );
3. 답
module top_module(
input a,
input b,
input sel_b1,
input sel_b2,
output wire out_assign,
output reg out_always );
assign out_assign = (sel_b1&sel_b2)?b:a;
always@(*)
begin
if(sel_b1&sel_b2) begin
out_always <= b;
end else begin
out_always <= a;
end
end
endmodule
'Verilog > HDLbits' 카테고리의 다른 글
| [HDLBits] Always case (0) | 2025.11.23 |
|---|---|
| [HDLBits] Always if2 (0) | 2025.11.23 |
| [HDLBits] Alwaysblock2 (0) | 2025.11.18 |
| [HDLBits] Alwaysblock1 (0) | 2025.11.18 |
| [HDLBits] Module addsub (0) | 2025.11.18 |