-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathex-basics-logic-mbit.v
54 lines (38 loc) · 1.68 KB
/
ex-basics-logic-mbit.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
module top;
// Declare multi-bit logic variables
logic [ 3:0] A; // 4-bit logic variable
logic [ 3:0] B; // 4-bit logic variable
logic [ 3:0] C; // 4-bit logic variable
logic [11:0] D; // 12-bit logic variable
initial begin
// Multi-bit literals
A = 4'b0101; $display( "4'b0101 = %x", A );
D = 12'b1100_1010_0101; $display( "12'b1100_1010_0101 = %x", D );
D = 12'hca5; $display( "12'hca5 = %x", D );
D = 12'd1058; $display( "12'd1058 = %x", D );
// Bitwise logical operators for doing AND, OR, XOR, and NOT
A = 4'b0101;
B = 4'b0011;
C = A & B; $display( "4'b0101 & 4'b0011 = %b", C );
C = A | B; $display( "4'b0101 | 4'b0011 = %b", C );
C = A ^ B; $display( "4'b0101 ^ 4'b0011 = %b", C );
C = A ^~ B; $display( "4'b0101 ^~ 4'b0011 = %b", C );
C = ~B; $display( "~4'b0011 = %b", C );
// Bitwise logical operators when some bits are X
A = 4'b0101;
B = 4'b00xx;
C = A & B; $display( "4'b0101 & 4'b00xx = %b", C );
C = A | B; $display( "4'b0101 | 4'b00xx = %b", C );
C = A ^ B; $display( "4'b0101 ^ 4'b00xx = %b", C );
C = A ^~ B; $display( "4'b0101 ^~ 4'b00xx = %b", C );
C = ~B; $display( "~4'b00xx = %b", C );
// Reduction operators
A = 4'b0101;
C = &A; $display( " & 4'b0101 = %b", C );
C = ~&A; $display( "~& 4'b0101 = %b", C );
C = |A; $display( " | 4'b0101 = %b", C );
C = ~|A; $display( "~| 4'b0101 = %b", C );
C = ^A; $display( "^ 4'b0101 = %b", C );
C = ^~A; $display( "^~ 4'b0101 = %b", C );
end
endmodule