-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4x1_MUX.py
48 lines (39 loc) · 1.02 KB
/
4x1_MUX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pyrtl
# Declaration
input0 = pyrtl.Input(1, "input0")
input1 = pyrtl.Input(1, "input1")
input2 = pyrtl.Input(1, "input2")
input3 = pyrtl.Input(1, "input3")
s0 = pyrtl.Input(1, "selector0")
s1 = pyrtl.Input(1, "selector1")
out = pyrtl.Output(1, "out")
# MUX logic
out <<= (
(input0 & ~s1 & ~s0)
| (input1 & ~s1 & s0)
| (input2 & s1 & ~s0)
| (input3 & s1 & s0)
)
print("--- 4 x 1 MUX Implementation ---")
# Simulation
sim_trace = pyrtl.SimulationTrace()
sim = pyrtl.Simulation(tracer=sim_trace)
# Test one case of an input set: "input0": 1, "input1": 0, "input2": 1, "input3": 0
for s0_val in range(2):
for s1_val in range(2):
sim.step(
{
"input0": 1,
"input1": 0,
"input2": 1,
"input3": 0,
"selector0": s0_val,
"selector1": s1_val,
}
)
sim_trace.print_trace()
print("")
sim_trace.render_trace(
["input0", "input1", "input2", "input3", "selector0", "selector1"]
)
exit(0)