Professional Documents
Culture Documents
Search
SystemC Tutorial
SystemC Introduction
SystemC Hello World
SystemC Operators SystemC Data Types
SystemC Operators
Arithmetic Operators SystemC Statement and Flow Control
SystemC Jump Statements
Arithmetic operators are used to perform arithmetic operation on numbers. SystemC Functions
SystemC Functions argument passing
Operator Description
SystemC Modules
+ Addition Add the two operands.
Subtraction Subtract the second operand from the first
Contact / Report an issue
operand. Your valuable inputs are
* Multiplication Multiply the two operands. required to improve the quality.
/ Division Divide the first operand by the second
operand. Follow Us
% Modulus Modulo operation.
Example1: Addition Operator
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 10;
int b = 20;
int c;
//addition operator,
c = a + b;
cout <<"Value of c = " << c << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of c = 30
Execute the above code on
Increment and Decrement
Operator Description
++ Increment Increment the operand by one and store the result in the
operand.
Decrement Decrement the operand by one and store the result in the
operand.
Pre Increment and Pre Decrement:
In Pre Increment/Decrement, operator is specified before the operand.
The pre increment/decrement performs the operation first and returns the new value.
Post Increment and Post Decrement:
In Post Increment/Decrement, operator is specified after the operand.
The post increment/decrement returns the old value while the new value of the operation is stored in the
operand.
Example1: PreIncrement
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 5;
//pre‐increment
cout <<"Value of a = " << ++a << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of a = 6
Execute the above code on
Example2: PostIncrement
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 5;
cout <<"Value of a = " << a++ << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of a = 5
Execute the above code on
Bitwise Operators
Operator Description
& AND operator Calculate the bitwise AND of the two operands.
| OR operator Calculate the bitwise OR of the two operands.
^ XOR operator Calculate the bitwise XOR of the two operands.
Example1: Bitwise AND Operator
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 1;
int b = 1;
int c;
//bitwise AND operator,
c = a & b;
cout <<"Value of c = " << c << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of c = 1
Execute the above code on
Arithmetic and Bitwise assignment
Operator Description
+= Add the two operands; assign the result to the first operand.
= Subtract the second operand from the first operand; assign the result to the
first operand.
*= Multiply the two operands; assign the result to the first operand.
/= Divide the first operand by the second operand; assign the result to the first
operand.
%= Modulo operation; assign the result to the first operand.
&= Calculate the bitwise AND of the two operands; assign the result to the first
operand.
|= Calculate the bitwise OR of the two operands; assign the result to the first
operand.
^= Calculate the bitwise XOR of the two operands; assign the result to the first
operand.
Example1: += Operator
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 10;
int b = 20;
//+= operator, Arithmetic and bitwise assignment
a += b;
cout <<"Value of a = " << a << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of a = 30
Execute the above code on
Example2: &= Operator
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 1;
int b = 0;
//&= operator, Arithmetic and bitwise assignment
a &= b;
cout <<"Value of a = " << a << endl;
return 0;// Terminate simulation
}
Simulator Output:
Value of a = 0
Execute the above code on
Equality and Relation
Operator Description
== equal Return true if the operands are equal.
!= not equal Return true if the operands are not equal.
< less than Return true if the first operand is less than the second
operand.
<= less than or equal to Return true if the first operand is less than or equal to
the second operand.
> greater than Return true if the first operand is greater than the
second operand.
>= greater than or equal Return true if the first operand is greater than or equal
to to the second operand.
Example1: == Operator
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
int a = 10;
int b = 20;
// == operator, Equality and relation
if(a == b)
cout <<"a is equals to b"<< endl;
else
cout <<"a is not equals to b"<< endl;
return 0;// Terminate simulation
}
Simulator Output:
a is not equals to b
Execute the above code on
© Copyright 2016 Verification Guide. All rights reserved.