|
|
The Vera arithmetic operators (+ - * / % and unary -) perform the respective operations on the two's complement representation of their operands. Operands must be of integral type, and the integer X value is interpreted as 32'bx. The result is of type integer if all operands are of type integer or enum, and is of type bit vector if any operand is a reg or bit vector. If any operand contains an unknown (x) or high impedence (z) values, the result becomes unknown (x). The unary arithmetic operator (-) takes precedence over the binary arithmetic operators. |
|
|
1 program arithmetic {
2 integer a,b,c;
3 bit [15:0] d,e,f;
4 integer ra,rs,rm,rd,rmo;
5 a = 10;
6 b = 100;
7 c = 1000;
8 d = 2;
9 e = 20;
10 f = 200;
11 // Binary operators
12 ra = a + b; // Addition
13 rs = a - b; // Subtraction
14 rm = c * d; // Multiplication
15 rd = f / b; // Divion
16 rmo = b % 3; // Modulo
17
18 printf("Binary Addition of %5d with %5d is %5d\n",a,b,ra);
19 printf("Binary Subtraction of %5d with %5d is %5d\n",a,b,rs);
20 printf("Binary Muliplication of %5d with %5d is %5d\n",c,d,rm);
21 printf("Binary Divion of %5d with %5d is %5d\n",f,b,rd);
22 printf("Binary Modulo of %5d with %5d is %5d\n",b,3,rmo);
23
24 // Unary operators
25 ra = - rs; // Assigning Negative value of rs
26 rs = - b; // Assigning Negative value of b
27
28 printf("Unary - of %5d is %5d\n",(a-b),ra);
29 printf("Unary - of %5d is %5d\n",b,rs);
30
31 }
You could download file arithmetic.vr here
|