-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathex-basics-logic-shift.v
45 lines (29 loc) · 1.28 KB
/
ex-basics-logic-shift.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
module top;
logic [7:0] A;
logic [7:0] B;
logic [7:0] C;
initial begin
// Fixed shift amount for logical shifts
A = 8'b1110_0101;
C = A << 1; $display( "8'b1110_0101 << 1 = %b", C );
C = A << 2; $display( "8'b1110_0101 << 2 = %b", C );
C = A << 3; $display( "8'b1110_0101 << 3 = %b", C );
C = A >> 1; $display( "8'b1110_0101 >> 1 = %b", C );
C = A >> 2; $display( "8'b1110_0101 >> 2 = %b", C );
C = A >> 3; $display( "8'b1110_0101 >> 3 = %b", C );
// Fixed shift amount for arithmetic shifts
A = 8'b0110_0100;
C = $signed(A) >>> 1; $display( "8'b0110_0100 >>> 1 = %b", C );
C = $signed(A) >>> 2; $display( "8'b0110_0100 >>> 2 = %b", C );
C = $signed(A) >>> 3; $display( "8'b0110_0100 >>> 3 = %b", C );
A = 8'b1110_0101;
C = $signed(A) >>> 1; $display( "8'b1110_0101 >>> 1 = %b", C );
C = $signed(A) >>> 2; $display( "8'b1110_0101 >>> 2 = %b", C );
C = $signed(A) >>> 3; $display( "8'b1110_0101 >>> 3 = %b", C );
// Variable shift amount for logical shifts
A = 8'b1110_0101;
B = 8'd2;
C = A << B; $display( "8'b1110_0101 << 2 = %b", C );
C = A >> B; $display( "8'b1110_0101 >> 2 = %b", C );
end
endmodule