-
Notifications
You must be signed in to change notification settings - Fork 17
/
ex-basics-case.v
57 lines (40 loc) · 942 Bytes
/
ex-basics-case.v
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
49
50
51
52
53
54
55
56
57
module top;
// Declaring Variables
logic [1:0] sel;
logic [7:0] a;
initial begin
// case statement
sel = 2'b01;
case ( sel )
2'b00 : a = 8'h0a;
2'b01 : a = 8'h0b;
2'b10 : a = 8'h0c;
2'b11 : a = 8'h0d;
default : a = 8'h0e;
endcase
$display( "sel = 01, a = %x", a );
// case statement w/ X
sel = 2'bxx;
case ( sel )
2'b00 : a = 8'h0a;
2'b01 : a = 8'h0b;
2'b10 : a = 8'h0c;
2'b11 : a = 8'h0d;
default : a = 8'h0e;
endcase
$display( "sel = xx, a = %x", a );
// Do not use x's in the case
// selection items
sel = 2'bx0;
case ( sel )
2'b00 : a = 8'h0a;
2'b01 : a = 8'h0b;
2'b10 : a = 8'h0c;
2'b11 : a = 8'h0d;
2'bx0 : a = 8'h0e;
2'bxx : a = 8'h0f;
default : a = 8'h00;
endcase
$display( "sel = x0, a = %x", a );
end
endmodule