Tutorials OPERATORS PART 1

Operators : Concatenation Arithmetic Operators Relational Operators Equality Operators Logical Operators Bit-wise Operators Reduction Operators Shift Operators Increment and Decrement Operators Conditional Operator

Concatenation :

{} concatenation right of assignment.
Â´{} concatenation left of assignment.

EXAMPLE :Concatenation
program main {
bit [4:0] a;
bit b,c,d;
b = 0;
c = 1;
d = 1;
a = {b,c,0,0,d};
`{b,c,d} = 3'b111;
printf(" a %b b %b c %b d %b ",a,b,c,d);
}

RESULTS

a 00001 b 1 c 1 d 1

Arithmetic :

# - unary arithmetic (negative)
# +, -, *, / binary arithmetic
# % modulus

EXAMPLE :Arithmetic
program main {
integer a,b;
b = 10;
a = 22;

printf(" -(nagetion) is %0d \n",-(a) );
printf(" a + b is %0d \n",a+b);
printf(" a - b is %0d \n",a-b);
printf(" a * b is %0d \n",a*b);
printf(" a / b is %0d \n",a/b);
printf(" a modulus b is %0d \n",a%b);

}

RESULTS

-(nagetion) is -22
a + b is 32
a - b is 12
a * b is 220
a / b is 2
a modules b is 2

Relational :

# > >= < <= relational

EXAMPLE :Relational
program main {
integer a,b;
b = 10;
a = 22;

printf(" a < b is %0d \n",a < b);
printf(" a > b is %0d \n",a >b);
printf(" a <= b is %0d \n",a <= b);
printf(" a >= b is %0d \n",a >= b);

}
RESULTS

a < b is 0
a > b is 1
a <= b is 0
a >= b is 1

Equality : == logical equality != logical inequality === case equality !== case inequality =?= wildcard equality !?= wildcard inequality

EXAMPLE :logical Equality
reg[3:0] a;
reg[7:0] x, y, z;
a = 4'b0101;
x = 8'b1000_0101;
y = 8'b0000_0101;
z = 8'b0xx0_0101;
if (x == a)
printf("x equals a is TRUE.\n");
if (y == a)
printf("y equals a is TRUE.\n");
if (z == a)
printf("z equals a is TRUE.\n");
RESULTS

y equals a is TRUE.

EXAMPLE : Case equality
program main {
reg a_1,a_0,a_x,a_z;
reg b_1,b_0,b_x,b_z;
a_1 = 'b1;a_0 = 'b0;a_x = 'bx;a_z = 'bz;
b_1 = 'b1;b_0 = 'b0;b_x = 'bx;b_z = 'bz;
printf("--------------------------\n");
printf (" == 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 == b_0,a_0 == b_1,a_0 == b_x,a_0 == b_z);
printf (" 1 %b %b %b %b \n",a_1 == b_0,a_1 == b_1,a_1 == b_x,a_1 == b_z);
printf (" x %b %b %b %b \n",a_x == b_0,a_x == b_1,a_x == b_x,a_x == b_z);
printf (" z %b %b %b %b \n",a_z == b_0,a_z == b_1,a_z == b_x,a_z == b_z);
printf("--------------------------\n");
printf("--------------------------\n");
printf (" === 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 === b_0,a_0 === b_1,a_0 === b_x,a_0 === b_z);
printf (" 1 %b %b %b %b \n",a_1 === b_0,a_1 === b_1,a_1 === b_x,a_1 === b_z);
printf (" x %b %b %b %b \n",a_x === b_0,a_x === b_1,a_x === b_x,a_x === b_z);
printf (" z %b %b %b %b \n",a_z === b_0,a_z === b_1,a_z === b_x,a_z === b_z);
printf("--------------------------\n");
printf("--------------------------\n");
printf (" =?= 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 =?= b_0,a_0 =?= b_1,a_0 =?= b_x,a_0 =?= b_z);
printf (" 1 %b %b %b %b \n",a_1 =?= b_0,a_1 =?= b_1,a_1 =?= b_x,a_1 =?= b_z);
printf (" x %b %b %b %b \n",a_x =?= b_0,a_x =?= b_1,a_x =?= b_x,a_x =?= b_z);
printf (" z %b %b %b %b \n",a_z =?= b_0,a_z =?= b_1,a_z =?= b_x,a_z =?= b_z);
printf("--------------------------\n");
printf("--------------------------\n");
printf (" != 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 != b_0,a_0 != b_1,a_0 != b_x,a_0 != b_z);
printf (" 1 %b %b %b %b \n",a_1 != b_0,a_1 != b_1,a_1 != b_x,a_1 != b_z);
printf (" x %b %b %b %b \n",a_x != b_0,a_x != b_1,a_x != b_x,a_x != b_z);
printf (" z %b %b %b %b \n",a_z != b_0,a_z != b_1,a_z != b_x,a_z != b_z);
printf("--------------------------\n");
printf("--------------------------\n");
printf (" !== 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 !== b_0,a_0 !== b_1,a_0 !== b_x,a_0 !== b_z);
printf (" 1 %b %b %b %b \n",a_1 !== b_0,a_1 !== b_1,a_1 !== b_x,a_1 !== b_z);
printf (" x %b %b %b %b \n",a_x !== b_0,a_x !== b_1,a_x !== b_x,a_x !== b_z);
printf (" z %b %b %b %b \n",a_z !== b_0,a_z !== b_1,a_z !== b_x,a_z !== b_z);
printf("--------------------------\n");
printf("--------------------------\n");
printf (" !?= 0 1 x z \n");
printf("--------------------------\n");
printf (" 0 %b %b %b %b \n",a_0 !?= b_0,a_0 !?= b_1,a_0 !?= b_x,a_0 !?= b_z);
printf (" 1 %b %b %b %b \n",a_1 !?= b_0,a_1 !?= b_1,a_1 !?= b_x,a_1 !?= b_z);
printf (" x %b %b %b %b \n",a_x !?= b_0,a_x !?= b_1,a_x !?= b_x,a_x !?= b_z);
printf (" z %b %b %b %b \n",a_z !?= b_0,a_z !?= b_1,a_z !?= b_x,a_z !?= b_z);
printf("--------------------------\n");
}

RESULTS

--------------------------
== 0 1 x z
--------------------------
0 1 0 x x
1 0 1 x x
x x x x x
z x x x x
--------------------------
--------------------------
=== 0 1 x z
--------------------------
0 1 0 0 0
1 0 1 0 0
x 0 0 1 0
z 0 0 0 1
--------------------------
--------------------------
=?= 0 1 x z
--------------------------
0 1 0 1 1
1 0 1 1 1
x 1 1 1 1
z 1 1 1 1
--------------------------
--------------------------
!= 0 1 x z
--------------------------
0 0 1 x x
1 1 0 x x
x x x x x
z x x x x
--------------------------
--------------------------
!== 0 1 x z
--------------------------
0 0 1 1 1
1 1 0 1 1
x 1 1 0 1
z 1 1 1 0
--------------------------
--------------------------
!?= 0 1 x z
--------------------------
0 0 1 0 0
1 1 0 0 0
x 0 0 0 0
z 0 0 0 0
--------------------------

 << PREVIOUS PAGE TOP NEXT PAGE >>
{"ft_lang_label":"__label__en","ft_lang_prob":0.5750529,"math_prob":0.9998909,"size":1857,"snap":"2021-21-2021-25","text_gpt3_token_len":708,"char_repetition_ratio":0.39341608,"word_repetition_ratio":0.19240506,"special_character_ratio":0.68282175,"punctuation_ratio":0.14285715,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99995744,"pos_list":[0,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],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-10T03:43:26Z\",\"WARC-Record-ID\":\"<urn:uuid:32c55727-b583-46aa-b6f0-da594738ee06>\",\"Content-Length\":\"37223\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1c9a7190-5aed-48a8-a7e8-d5294579b83f>\",\"WARC-Concurrent-To\":\"<urn:uuid:9a941a3d-4134-4bcc-8a09-70f39bc31475>\",\"WARC-IP-Address\":\"160.153.74.70\",\"WARC-Target-URI\":\"http://testbench.in/OV_04_OPERATORS_PART_1.html\",\"WARC-Payload-Digest\":\"sha1:57RVBVCGPSF3A4D4EGVJNS4Q6UVIZUSD\",\"WARC-Block-Digest\":\"sha1:C6WZXDEJE2LDXPJY5BEYOPXRJCVY2VZP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243989030.87_warc_CC-MAIN-20210510033850-20210510063850-00120.warc.gz\"}"}