How to Run SystemC code in EDA playground

How to Run SystemC programs using EDA play ground

Examples are already present for easy understanding  SystemC Examples

For example lets consider SystemC  counter example,

Below steps to Run the program:
1. Make below settings
Ø Testbench + Design C++/SystemC
Ø Libraries Systemc 2.3.1
Ø Tools and Simulators C++
2. Write Testbench code in testbench.cpp
3. Write Source code in design.cpp
4. Run the program
5. You can view the result in log window
6. If you want to view the waveform

Tick Open EPWave after run
*waveform window appears after the run automatically

SystemC Data Types

SystemC supports all C++ data types; in addition SystemC provides additional data types for describing hardware.Data types are explained in two parts,

  1. C++ data types
  2. SystemC data types

 C++ Data Types 

C++ data types can be divided into two categories,
  • Fundamental datatypes
  • Additional datatypes

 Fundamental Data Types: 

 
Data Types
Keyword
Description
Character types
char
character with  width of 8bits
wchar_t
Represents the largest character set
Integer types
int
integer with width of 32 bits
signed int
signed integer with width of 32 bits, values can be
+ve/-ve/’0’
unsigned int
unsigned integer with width of 32 bits, values must be
+ve/’0’
short
Short integer with width of 16 bits
signed short
signed short integer with width of 16 bits, values can
be +ve/-ve/’0’
unsigned short
Unsigned Short integer with width of 16 bits, values
must be +ve/’0’
long
Long integer with width of 32 bits
signed long
Signed long integer with width of 32 bits, values can
be +ve/-ve/’0’
unsigned long
Unsigned long integer with width of 32 bits, values
must be +ve/’0’
Floating-point types
float
Floating point number with width of 32bits.
double
Double precision floating point number with width of
64bits.
long double
Long precision floating point number with width of
64bits.
Boolean type
bool
Boolean type with size of 8bits,it can take values
‘0’/’1’
Void type
void
With no value


Declaration:
                      Int     a;
                      Float b;

 

Example-1: Initialization and Declaration

#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  //variable declaration
  int a;
  float b;
  float c;
  
  //initialization
  a = 10;
  b = 20.5;
  
  //addtion
  c = a + b;
  
  cout <<"Value of a = "<< c <<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

Value of a = 30.5
Execute the above code on 

Example-2: Declaration and Initialization

#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  
  //variable declaration and initialization
  //variables can be initialized in three different ways as shown below
  int   a=10;
  int   b(1.3);
  float c{2.8}; 
    
  cout <<"Value of a = "<< a <<endl;
  cout <<"Value of b = "<< b <<endl;
  cout <<"Value of c = "<< c <<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

Value of a = 10
Value of b = 1
Value of c = 2.8
Execute the above code on 

Example-3: Initializing char


#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  
  //variable declaration and initialization
  char a[] = "Hello world";
  char b[5];

  //initialization
  b[0] = 'H';
  b[1] = 'e';
  b[2] = 'l';
  b[3] = 'l';
  b[4] = 'o';
  
  //below initializations types are not allowed
  //b = "Hello";
  //b = {'H','e','l','l','o'};
  
  cout <<"Value of a = "<< a <<endl;
  cout <<"Value of b = "<< b <<endl;
  
  // Terminate simulation
  return 0;
}

Simulator Output:

Value of a = Hello world
Value of b = Hello

Execute the above code on 

 

 

 Additional Data Types: 

  • String Data Types
  • Enumerated Data Types
  • Typedef Data Types

String Types:

As Fundamental data types, we cant use the string data type directly. To use string data type need to import the string header standard library.( #include <string>)

 

Example-4: enum example

#include "systemc.h"
#include <string>
using namespace std;

int sc_main (int argc, char* argv[]) {
  
  //string declaration and initialization
  string mystring   = "Hello world";
  string mystring_1;
  string mystring_2;
  string mystring_3;
  
  //initialization, can be initialized in three ways.
  mystring_1 =  "1. I am String in C++/SystemC";
  mystring_2 = ("2. I am String in C++/SystemC");
  mystring_3 = {"3. I am String in C++/SystemC"};
  
  cout <<"mystring   = "<< mystring <<endl;
  cout <<"mystring_1 = "<< mystring_1 <<endl;
  cout <<"mystring_2 = "<< mystring_2 <<endl;
  cout <<"mystring_3 = "<< mystring_3 <<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

mystring_1 = 1. I am String in C++/SystemC
mystring_2 = 2. I am String in C++/SystemC
mystring_3 = 3. I am String in C++/SystemC
Execute the above code on 
Enumerated Types:
 

An enumerated type defines a set of named values. The simplest enumerated type declaration contains a list of constant names and one or more variables.enum type_name {value1,value2,…,valuen} object_names;

This creates the type type_name, which can take any of value1, value2, … ,valuen as value. Variables of this type can directly be instantiated as object_names.
In the following example, colors is defined to be variable of the Colors type that includes the members red, green, blue, yellow, white, black.

enum Colors { red, green, blue, yellow, white, black } Color_t;

Color_t can be used directly used as variable, but Colors is used as type to declare the variables.

Example-5: Enum Example


#include "systemc.h"

int sc_main (int argc, char* argv[]) {

  //declaration
  enum Colors { red, green, blue, yellow, white, black } Colors_t;
  Colors my_color;
  
  Colors_t = white;
  my_color = blue;
  
  cout <<"Colors_t   = "<< Colors_t <<endl;
  cout <<"mystring   = "<< my_color <<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

Colors_t = 4
mystring = 2
Execute the above code on 

The actual values are default to integers starting at 0 and then increase. in the above example by default variable will get default value of 0,1,2,3,4,5 respectively from  red.

The values can be set for the names and also values can be set for some of the names and not set for other names. A name without a value is automatically assigned an increment of the value of the previous name.

In the following example value is set for green = 2, yellow = 8.

enum Colors { red, green=2, blue, yellow=8, white, black };

Example-6: Enum Example

#include "systemc.h"

int sc_main (int argc, char* argv[]) {

  //declaration
  enum Colors { red, green=2, blue, yellow=8, white, black };
  Colors my_color;
  
  my_color = blue;
  cout <<"my_color value is = "<< my_color <<endl;

  my_color = black;
  cout <<"my_color value is = "<< my_color <<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

my_color value is = 3
my_color value is = 10
Execute the above code on 
 
Typedef Data Types:
 
The user can define a new type using typedef,
            typedef int integre_v;
            This can then be instantiated as:
                     integer_v var1;
                     integer_v var2;

Constant Expressions:

Constant values can be named by using const keyword.

Example-1: Constant

#include "systemc.h"
const int seconds_per_minute = 60;

int sc_main (int argc, char* argv[]) {

  cout <<"1 minute = "<< seconds_per_minute << " seconds"<<endl;
  cout <<"8 minute = "<< 8*seconds_per_minute << " seconds"<<endl;
  
  // Terminate simulation
  return 0;
}

 

Simulator Output:

1 minute = 60 seconds
8 minute = 480 seconds
Execute the above code on 
❮ Previous Next ❯

SystemC int bit logic

 Fixed-Precision Integer Types  

sc_int and sc_unit are the fixed-precision integer types.
Syntax:
            sc_int<w>
            sc_uint<w>
             where w specifies the width.
sc_int and sc_unit are of integer type, with the width can be explicitly specified.The maximum precision is limited to 64 bits, Therefore these types are called as Fixed-Precision type.
sc_int is signed.
sc_uint is unsigned.
Bit select, part select, concatenation and reduction operators are supported.
Declaration Examples:
            sc_int<4>     a;  //a of sc_int  type with width ‘4’ bit
            sc_uint<6>   b;  //b of sc_uint type with width ‘6’ bit

 Arbitrary Precision Integer Types 

sc_bigint and sc_bigunit are the Arbitrary  precision integer types,
Syntax:
            sc_int<w>
            sc_uint<w>
             where w specifies the width.Syntax,
sc_bigint and sc_biguint are of integer type.
sc_bigint is signed.
sc_biguint is unsigned.
Bit select, part select, concatenation and reduction operators are supported.
Declaration Examples:
            sc_bigint<4>     a;  //a of sc_bigint  type
            sc_biguint<6>   b;  //b of sc_biguint type

 Arbitrary Width Bit Vectors 

A bit vector shall implement a multiple bit data type where each bit has a state of logic 0 or logic 1 and is represented by the symbols ‘0’ or ‘1’, respectively.
Syntax:
            sc_bv<w>
Bit select, part select, concatenation and reduction operators are supported.

 Logic Type 

logic types implement a four-valued logic data type with states logic 0, logic 1, high-impedance,
and unknown and shall be represented by the symbols ‘0’, ‘1’, ‘X’, and ‘Z’, respectively.
Syntax:
            sc_logic
Bit select, part select, concatenation and reduction operators are supported.

❮ Previous Next ❯

SystemC Modules

 SystemC Modules 

Modules are the building blocks of SystemC, It is a container class that  may contain data members, channel members, processes, instance of other modules and ports for communication.

Modules are extended from sc_module, in other words modules are the child classes of sc_module Class.
Example:

class module_name : public sc_module {
. . .
};

Also module may be created with use of the SC_MODULE macro as follows,

Example:
SC_MODULE( module_name ) {
……
};

Constructor

SC_CTOR macro declares the constructor, module must have SC_CTOR or it can have SC_HAS_PROCESS.(will see the SC_HAS_PROCESS in next chapters)

by default SC_CTOR macro has one argument which is the name of the module.

Example:
SC_MODULE( module_name ) {
SC_CTOR(module_name){ }
};

Constructor to initialize the module properties:

Module Instance:
Module instance can be created as below,
module_name instance_name(“instance_name”);

Example:
SC_MODULE( module_1 ) {

};
❮ Previous Next ❯

SystemC Functions argument passing

 functions argument passing 

SystemC/C++ provides below means for passing arguments to functions,
  • pass by value
  • pass by reference

 pass by value 

In argument pass by value, argument passing mechanism works by copying each argument into the subroutine area. if any changes to arguments with in the subroutine, those changes will not be visible outside the subroutine.

 Example-1:

The example below shows argument pass by value.
variables x and y are passed as an argument in the function call sum, changes to the argument x with in the function is not visible outside.
#include "systemc.h"

//function sum
int sum (int x,int y)
{ 
  return x = x+y;
}

int sc_main (int argc, char* argv[]) {
  int x=20;
  int y=30;
  int z;
  
  //function call
  z=sum(x,y);
  
  //value of x,y and z
  cout <<"Value of x="<<x<<endl;  
  cout <<"Value of y="<<y<<endl; 
  cout <<"Value of z="<<z<<endl; 
  // Terminate simulation
  return 0;
}

 Simulator Output: 

Value of x=20
Value of y=30
Value of z=50
Execute the above code on 

  argument pass by reference 

reference to the original argument is passed to the subroutine. as the argument with in subroutine is pointing to an original argument, any changes to the argument with in subroutine will be visible outside. To indicate argument pass by reference, the argument type is suffix with &.

 Example-2 

The example below shows argument pass by reference.
variables x and y are passed as an argument in the function call sum, changes to the argument x with in the function, is visible outside.
#include "systemc.h"

//function sum
int sum (int& x,int& y)
{ 
  return x = x+y;
}

int sc_main (int argc, char* argv[]) {
  int x=20;
  int y=30;
  int z;
  
  //function call
  z=sum(x,y);
  
  //value of x,y and z
  cout <<"Value of x="<<x<<endl;  
  cout <<"Value of y="<<y<<endl; 
  cout <<"Value of z="<<z<<endl; 
  // Terminate simulation
  return 0;
}

 Simulator Output: 

Value of x=50
Value of y=30
Value of z=50

Execute the above code on 

 const keyword 

Any modifications to the argument value in pass by reference can be avoided by using const keyword before argument type, any attempt in changing the argument value in subroutine will lead to compilation error.

 Example-3 

The example below shows argument pass by reference with const keyword.
variables x and y are passed as an argument in the function call sum, as arguments are mentioned as const, changes to the argument x with in the function leads to compilation error.
#include "systemc.h"

//function sum
int sum (const int& x,const int& y)
{ 
  return x = x+y;
}

int sc_main (int argc, char* argv[]) {
  int x=20;
  int y=30;
  int z;
  
  //function call
  z=sum(x,y);
  
  //value of x,y and z
  cout <<"Value of x="<<x<<endl;  
  cout <<"Value of y="<<y<<endl; 
  cout <<"Value of z="<<z<<endl; 
  // Terminate simulation
  return 0;
}

 Simulator Output: 

testbench.cpp: In function ‘int sum(const int&, const int&)’:
testbench.cpp: error: assignment of read-only reference ‘x’
Exit code expected: 0, received: 1
Execute the above code on 

 default argument values 

default value can be specified to the arguments of subroutine.
In the subroutine call, arguments with default value can be omitted from the call. if any value is passed to an argument with default value, then the new value will be considered.

 Example-4 

The example below shows argument with default value.

#include "systemc.h"

//function sum
int sum (int x=10,int y=20)
{ 
  return x = x+y;
}

int sc_main (int argc, char* argv[]) {
  int z;
  
  //function takes defalut values for arguments
  z=sum();
  cout <<"Value of z="<<z<<endl; 
  
  //function takes default value for second argument
  z=sum(20);
  cout <<"Value of z="<<z<<endl; 

  // Terminate simulation
  return 0;
}

 Simulator Output: 

Value of z=30
Value of z=40
Execute the above code on 
❮ Previous Next ❯

SystemC Functions

 Functions 

function is group of statements to perform the specific task.

Syntax:


type function_name (arguments) {
function_body;
}

where,
         type – functions will return an value, type specifies the return type
         function_name – name of the function
         arguments – arguments to the function
        function_body – body of the function, which may contain declarations, assignments, expressions etc.
function can return a specific value by specifying return in function body, otherwise the result of last expression will be returned.

Example-1:

 
#include "systemc.h"

//function add, to add two integer numbers
int add (int a,int b)
{
 return a+b; 
}

int sc_main (int argc, char* argv[]) {
  //declaration
  int x,y,z;
  
  //initialization
  x=10;
  y=20;
  
  //function calling
  z =  add(x,y);
  cout <<" x+y = "<<z<<endl;
    
  // Terminate simulation
  return 0;
}

Simulator Output:

x+y = 30
Execute the above code on 

 void functions 

Generally functions will return an value, where as void functions will not return any value.
by specifying type as void function can be declared as void function.

Example-1:

 
#include "systemc.h"

//function add, to add two integer numbers
void display (int a,int b)
{
 cout <<" recived a = "<<a<<" b = "<<b<<endl; 
}

int sc_main (int argc, char* argv[]) {
  
  //function calling
  display(10,20);
    
  // Terminate simulation
  return 0;
}

Simulator Output:

recived a = 10 b = 20
Execute the above code on 

 function call as expression 

Example-1:

 
#include "systemc.h"

//function add, to add two integer numbers
int add (int a,int b)
{
 return a+b; 
}

int sc_main (int argc, char* argv[]) {
  //declaration
  int x,y,z;
  
  //initialization
  x=10;
  y=20;
  
  //function call in expression
  z =  10 + add(x,y) + 20;
  cout <<" Value of z = "<<z<<endl;
    
  // Terminate simulation
  return 0;
}

Simulator Output:

Value of z = 60
Execute the above code on 

  functions declaration 

Example-1:

 
#include "systemc.h"

//function display_1
void display_1 ()
{
  display_2;
}

//function display_1
void display_2 ()
{
  display_1;
}

int sc_main (int argc, char* argv[]) {
    
  // Terminate simulation
  return 0;
}

Simulator Output:

testbench.cpp: In function ‘void display_1()’:
testbench.cpp: error: ‘display_2’ was not declared in this scope
Exit code expected: 0, received: 1

Execute the above code on 

The above example is locked situation where as display_1 is calling display_2 and display_2 is calling display_1, this leads to an compilation error.
This problem can be overcome by declaring the functions and writing the definitions separately.
Arguments  and type must match in declaration and definition.

Example-2:

 
#include "systemc.h"

void display_1();
void display_2();

//function display_1
void display_1 ()
{
  display_2();
}

//function display_1
void display_2 ()
{
  display_1();
}

int sc_main (int argc, char* argv[]) {
  cout <<"Inside Main"<<endl;
  // Terminate simulation
  return 0;
}

Simulator Output:

Inside Main
Execute the above code on 
❮ Previous Next ❯

SystemC Jump Statements

 Jump Statements: 

 break 

Execution of break statement leads to end of the loop.

Example-1: break

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {

  //break-example
  for(int i=0;i<8;i++) {
    cout <<" Value of i="<<i<<endl;
    if(i == 4) {
      cout <<" Calling break"<<endl;
      break;
    }
  }
           
  // Terminate simulation
  return 0;
}

Simulator Output:

j=0 i=4
j=1 i=3
j=2 i=2
j=3 i=1
Execute the above code on 

 continue 

Execution of continue statement leads to skip the execution of statements followed by continue and jump to next loop or iteration value.

 

Example-1: continue

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {

  //continue-example
  for(int i=0;i<5;i++) {
    cout <<"Before continue, value of i="<<i<<endl;
    if((i > 1) && (i < 4)) {
      cout <<"     Calling continue"<<endl;
      continue;
    }
    cout <<"After  continue, value of i="<<i<<endl;
  }
           
  // Terminate simulation
  return 0;
}

Simulator Output:

Before continue, value of i=0
After continue, value of i=0
Before continue, value of i=1
After continue, value of i=1
Before continue, value of i=2
Calling continue
Before continue, value of i=3
Calling continue
Before continue, value of i=4
After continue, value of i=4
Execute the above code on 

 goto 

Execution of goto leads to jump to another point in the program.

Example-1: goto

 
#include "systemc.h"
#include <iostream>
using namespace std;

int sc_main (int argc, char* argv[]) {
  //declaration and initialization
  int a = 15;
  int b = 10;
  
  my_lable:  
  cout <<" @ my_label "<<endl;

  if( a > b ) {
    cout <<" a is greater than b a = "<<a<<" b = "<<b<<endl;
    a--;
    goto my_lable;
  }
  else
    cout <<" b is greater than a "<<endl;
    
  // Terminate simulation
  return 0;
}

Simulator Output:

@ my_label
a is greater than b a = 15 b = 10
@ my_label
a is greater than b a = 14 b = 10
@ my_label
a is greater than b a = 13 b = 10
@ my_label
a is greater than b a = 12 b = 10
@ my_label
a is greater than b a = 11 b = 10
@ my_label
b is greater than a
Execute the above code on 
❮ Previous Next ❯

SystemC Statement and Flow Control

 Statements 

All the statements will end with semicolon (;), Number of statements can be grouped by placing them with in curly braces. { };
{
    Statement1;
    Statement2;
    Statement3;
}

  if and else 

The if  keyword is used to execute the statement or group of statements based on the condition’s.

Below are the few examples,

//if, execution of one statement on condition satisfied
if ( condition ) statement;
//if, execution of block/statement's on condition satisfied
if ( condition ) {
    Statement1;
    Statement2;
}
//if along with else part
if(condition) {
     Statement1;
}
else {
      stetement2;
}
//if, with nested if in else part
if(condition2) {
     Statement1;
}
else  if (condition2) {
   if(condition3)  stetement2;
   else            statement3;
}

Example-1:

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  //declaration and initialization
  int a = 10;
  int b = 30;
  
  //if-else 
  if( a > b )
    cout <<" a is greater than b "<<endl;
  else
  {
    cout <<" b is greater than a "<<endl;
    if((b-a) > a)
      cout <<" b-a is greater than a"<<endl;
    else 
      cout <<" b-a is less than a "<<endl;
  }
    
  // Terminate simulation
  return 0;
}

Simulator Output:



b is greater than a
b-a is greater than a

Execute the above code on 

 Loop Statements: 

Below are the loop statements in C++/SystemC,

  • For Loop
  • While Loop
  • Do-while

 for loop 

for (initialization; condition; increment/decrement) statement;
for loop works as below,
  • Initialize the loop variable
  • Check for the condition, if condition is satisfied then executes the block
  • Increment/decrement the loop variable value

Example-1: for-loop

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {

  //for-loop
  for(int i=0; i<4; i++)
  {
    cout <<" Value of i = "<<i<<endl;
  }
    
  // Terminate simulation
  return 0;
}

Simulator Output:

Value of i = 0
Value of i = 1
Value of i = 2
Value of i = 3
Execute the above code on 

Example-2: for-loop, one or more initial declaration

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {

  //for-loop
  for ( int j=0,i=3;j<5;j++)
  {
    if(j==i) 
      cout <<" Value j equals to Value of i. j="<<j<<" i="<<i<<endl;
     else
      cout <<" Value j ="<<j<<endl;
  }
    
  // Terminate simulation
  return 0;
}

Simulator Output:

Value j =0
Value j =1
Value j =2
Value j equals to Value of i. j=3 i=3
Value j =4
Execute the above code on 

Example-3: for-loop, one or more step assignment

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {

  //for-loop
  for ( int j=0,i=4;j<4;j++,i--)
  {
    cout <<" j="<<j<<" i="<<i<<endl;
  }
    
  // Terminate simulation
  return 0;
}

Simulator Output:

j=0 i=4
j=1 i=3
j=2 i=2
j=3 i=1
Execute the above code on 

 While Loop 

The while loop will repeats the execution of statement/block until the condition is true.

Example-1: while-loop

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  //declaration and initialization
  int a = 15;
  int b = 10;

  //while-loop
  while( a > b ) {
    cout <<" a is greater than b a = "<<a<<" b = "<<b<<endl;
    a--;
  }

  cout <<" b is greater than a "<<endl;
    
  // Terminate simulation
  return 0;
}

Simulator Output:

a is greater than b a = 15 b = 10
a is greater than b a = 14 b = 10
a is greater than b a = 13 b = 10
a is greater than b a = 12 b = 10
a is greater than b a = 11 b = 10
b is greater than a
Execute the above code on 

 Do-while 

The do-while loop will execute the statement/block and then checks for condition.
The difference between do-while and while is, irrespective of the condition the statement/block will be executed at least once in do-while.

Example-1: do-while

 
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
  //declaration and initialization
  int a = 9;
  int b = 10;

  //while-loop
  do{
    cout <<" a is greater than b a = "<<a<<" b = "<<b<<endl;
    a--;
  }while( a > b );

  cout <<" b is greater than a "<<endl;
    
  // Terminate simulation
  return 0;
}

Simulator Output:

a is greater than b a = 9 b = 10
b is greater than a
Execute the above code on 
❮ Previous Next ❯

SystemC Operators

 Arithmetic Operators 

Arithmetic operators are used to perform arithmetic operation on numbers.
Operator
Description
+
Addition
Add the two operands.
Subtraction
Subtract the second operand from the first operand.
*
Multiplication
Multiply the two operands.
/
Division
Divide the first operand by the second operand.
%
Modulus
Modulo operation.

 

Example-1: 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.

Example-1: Pre-Increment

 
#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 

Example-2: Post-Increment

#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.

 

Example-1: 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.

Example-1: += 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 

Example-2: &= 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 to
Return true if the first operand is greater than or equal to the second operand.

Example-1: == 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 

❮ Previous Next ❯