Skip to content

Commit a3575b0

Browse files
committed
feat: 250406 블로그 업로드
1 parent 4575aea commit a3575b0

2 files changed

Lines changed: 563 additions & 0 deletions
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
title: "[HDL Bits] 7.Circuits - Comb Logic - Multiplexers"
3+
date: 2025-04-06 21:30:00 +09:00
4+
categories: [Verilog, HDLbits]
5+
tags:
6+
[
7+
verilog,
8+
HDLbits,
9+
]
10+
---
11+
12+
# HDL Bits
13+
HDLBits는 Verilog 하드웨어 설명 언어(HDL)를 사용하여 디지털 하드웨어 설계를 연습할 수 있는 소규모 회로 설계 연습 문제 모음입니다.
14+
15+
문제가 주어지면 코드를 입력할 수 있고 바로 검증을 하여 맞고 틀렸는지 확인할 수 있습니다.
16+
17+
[HDL Bits](https://hdlbits.01xz.net/wiki/Main_Page)
18+
19+
# 2. Circuits
20+
Circuits 는 다음과 같은 목차로 구성되어 있다.
21+
- Circuits
22+
- Combinational Logic
23+
- Basic Gates
24+
- **Multiplexers**
25+
- Arithmetic Circuits
26+
- Karnaugh Map to Circuit
27+
- Sequential
28+
- LaTCHES AND Flip-Flops
29+
- Counters
30+
- Shift Registers
31+
- More Circuts
32+
- Finite State Machines
33+
- Building Larger Circuits
34+
35+
36+
오늘은 이 중 `Combinational Logic` 챕터의 `Multiplexers` 를 풀어볼 예정이이다.
37+
38+
## 3.3.2.1. 2-to-1 multiplexer (Mux2to1)
39+
### Module Declaration
40+
41+
```verilog
42+
module top_module(
43+
input a, b, sel,
44+
output out );
45+
46+
endmodule
47+
```
48+
49+
이번 문제는 1비트 너비의 2대 1 멀티플렉서를 만듭니다.
50+
51+
sel=0이면 a를 선택하고, sel=1이면 b를 선택합니다.
52+
53+
```verilog
54+
module top_module(
55+
input a, b, sel,
56+
output out );
57+
58+
assign out = sel ? b : a;
59+
// assign out = (sel & b) | (~sel & a);
60+
endmodule
61+
62+
```
63+
64+
65+
## 3.3.2.2. 2-to-1 bus multiplexer (Mux2to1v)
66+
### Module Declaration
67+
68+
```verilog
69+
module top_module(
70+
input [99:0] a, b,
71+
input sel,
72+
output [99:0] out );
73+
74+
endmodule
75+
76+
```
77+
78+
```verilog
79+
module top_module(
80+
input [99:0] a, b,
81+
input sel,
82+
output [99:0] out );
83+
84+
assign out = sel ? b : a;
85+
86+
endmodule
87+
```
88+
89+
90+
91+
92+
## 3.3.2.3. 9-to-1 multiplexer (Mux9to1v)
93+
### Module Declaration
94+
★★★☆☆
95+
```verilog
96+
module top_module(
97+
input [15:0] a, b, c, d, e, f, g, h, i,
98+
input [3:0] sel,
99+
output [15:0] out );
100+
101+
endmodule
102+
103+
```
104+
105+
```verilog
106+
module top_module(
107+
input [15:0] a, b, c, d, e, f, g, h, i,
108+
input [3:0] sel,
109+
output [15:0] out );
110+
111+
always@(*)begin
112+
case(sel)
113+
4'b0000 : out = a;
114+
4'b0001 : out = b;
115+
4'b0010 : out = c;
116+
4'b0011 : out = d;
117+
4'b0100 : out = e;
118+
4'b0101 : out = f;
119+
4'b0110 : out = g;
120+
4'b0111 : out = h;
121+
4'b1000 : out = i;
122+
default : out = 16'hffff;
123+
endcase
124+
end
125+
endmodule
126+
127+
128+
// 또는
129+
wire [143:0] inputs = {a, b, c, d, e, f, g, h, i};
130+
131+
assign out = (sel < 9) ? inputs[ (8 - sel)*16 +:16 ] : 16'hffff;
132+
```
133+
134+
135+
## 3.3.2.4. 256-to-1 multiplexer (Mux256to1)
136+
### Module Declaration
137+
★★☆☆☆
138+
```verilog
139+
module top_module(
140+
input [255:0] in,
141+
input [7:0] sel,
142+
output out );
143+
144+
endmodule
145+
```
146+
1비트 너비의 256대 1 멀티플렉서를 만듭니다.
147+
148+
256개의 입력은 모두 단일 256비트 입력 벡터에 포함됩니다.
149+
150+
sel=0은 [0]에서, sel=1은 [1]에서 비트를, sel=2는 [2]에서 비트를 선택해야 합니다.
151+
152+
153+
```verilog
154+
module top_module(
155+
input [255:0] in,
156+
input [7:0] sel,
157+
output out );
158+
159+
integer i;
160+
161+
always @(*) begin
162+
for ( i = 0; i<256; i++ ) begin
163+
if(sel == i) begin
164+
out = in[i];
165+
end
166+
end
167+
end
168+
endmodule
169+
170+
//또는
171+
172+
assign out = in[sel];
173+
```
174+
175+
176+
## 3.3.2.5. 256-to-1 4bit multiplexer
177+
### Module Declaration
178+
★★★☆☆
179+
```verilog
180+
module top_module(
181+
input [1023:0] in,
182+
input [7:0] sel,
183+
output [3:0] out );
184+
185+
endmodule
186+
187+
```
188+
189+
이번 문제는 4비트 너비의 256대 1 멀티플렉서를 만듭니다.
190+
191+
256개의 4비트 입력은 모두 단일 1024비트 입력 벡터에 포함됩니다.
192+
193+
sel=0은 [3:0]에서 비트를 선택하고, sel=1은 [7:4]에서 비트를 선택하며, sel=2는 [11:8]에서 비트를 선택합니다.
194+
195+
196+
197+
198+
199+
#### 다음에 계속
200+
201+
---

0 commit comments

Comments
 (0)