File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
src/main/scala/hdlbits/circuits Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ package hdlbits .circuits
2
+
3
+ import chisel3 ._
4
+ import chisel3 .util ._
5
+
6
+ // _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
7
+ import _root_ .circt .stage .ChiselStage
8
+
9
+ // Generate Verilog sources and save it in file Exams2014Q3c.sv
10
+ object HdlBitsExams2014Q3c extends App {
11
+ ChiselStage .emitSystemVerilogFile(
12
+ new HdlBitsExams2014Q3c ,
13
+ firtoolOpts = Array (
14
+ " -disable-all-randomization" ,
15
+ " -strip-debug-info"
16
+ ),
17
+ args = Array (" --target-dir" , " gen/hdlbits/circuits" )
18
+ )
19
+ }
20
+
21
+ // https://hdlbits.01xz.net/wiki/Exams/2014_q3c
22
+ class HdlBitsExams2014Q3c extends RawModule {
23
+ val clk = IO (Input (Clock ()))
24
+ val y = IO (Input (UInt (3 .W )))
25
+ val x = IO (Input (Bool ()))
26
+ val Y0 = IO (Output (Bool ()))
27
+ val z = IO (Output (Bool ()))
28
+
29
+ // Output logic
30
+ Y0 := false .B
31
+ z := false .B
32
+ switch(y) {
33
+ is(0 .U ) {
34
+ Y0 := x
35
+ z := false .B
36
+ }
37
+ is(1 .U ) {
38
+ Y0 := ~ x
39
+ z := false .B
40
+ }
41
+ is(2 .U ) {
42
+ Y0 := x
43
+ z := false .B
44
+ }
45
+ is(3 .U ) {
46
+ Y0 := ~ x
47
+ z := true .B
48
+ }
49
+ is(4 .U ) {
50
+ Y0 := ~ x
51
+ z := true .B
52
+ }
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments