|
|
1 program bitwise {
2 bit [7:0] data = 8'hA0;
3 bit [7:0] addr = 8'hA5;
4 bit [15:0] mem_addr = 16'h1234;
5 integer i = 32'hDEAD_BEEF;
6 bit [7:0] result = 0;
7 // Bitwise inversion
8 printf("Inversion of %b is %b\n",data, ~data);
9 // Bitwise AND
10 printf("AND of %b with %b is %b\n",data, addr,data & addr);
11 // Bitwise OR
12 printf("OR of %b with %b is %b\n",data, addr,data | addr);
13 // Bitwise XOR
14 printf("XOR of %b with %b is %b\n",data, addr,data ^ addr);
15 // Bitwise operation on integer and bit
16 result = i | data;
17 printf("OR of %b with %b is %b\n",data, i,result);
18 // Bitwise operation on different width operands
19 mem_addr = data ^ i;
20 printf("XOR of %b with %b is %b\n",data, i,mem_addr);
21 }
You could download file bitwise.vr here
|