SystemC Simulation Tutorial:
Design of a 1-bit Adder and a 4-bit Adder

I. Procedure

Setting up SystemC

  1. Start Microsoft Visual C++ 6.0
  2. Create a Project Workspace:
    1. Click on "File", then "New", select "Projects", then click on "Win32 Console Application".
    2. In the "Location" box, click on the down arrow, then on "Drives", and choose "h:\\some_server_name\cs1Xxx" , then click "OK" (some_server_name will have some name there (it changes periodically)) (csXxx is your login). You should not actually be typing anything here, just click.
    3. For the "Project Name", We will use "lab1a" as the example.
    4. Type "OK".
    5. Choose "An empty project" and click "Finish". Then click "OK".
  3. You can now see a folder named "lab1a classes" in the workspace window. (Left part of screen)
  4. Port SystemC libraries to Microsoft Visual C++ 6.0:
    1. Click on “Project”, then “Settings”, then select the C/C++ tab, and then finally select the “C++ Language” category. Make sure that the “Enable Run Time Type Information (RTTI)” checkbox is checked.
    2. Also make sure that the SystemC header files are included by  switching to the “Preprocessor” on the C/C++ tab and then typing “C:\SystemC\systemc-2.0.1\src” in the text entry field labeled “Additional include directories”.
    3. Next click on the “Link” tab, and make sure the SystemC library is included to your project by typing “C:\SystemC\systemc-2.0.1\msvc60\systemc\Debug” in the text entry field labeled “Additional library path”.
    4. Add the SystemC object files by first clicking on “Project”, then “Add to Project”, then “Files”. In the File Browser navigate to the “C:\SystemC\systemc-2.0.1\msvc60\systemc\Debug” directory. In the text entry field labeled “File Name” type “*.obj” and press enter. Click on the file “sc_attribute.obj” and then simultaneously press the “Ctrl” & “A” keys (CTRL+A). Click the OK button to add the files.
    5. In your workspace window under the “File View” Tab, you should see a number of object files with the “sc_” prefix such as sc_attribute.obj, sc_bit.obj, etc. Find the file “sc_isdb_trace.obj”, click that file name, and press “delete” on your keyboard.

Creating the 1-bit adder

  1. After creating  a new project by following the steps above, Click on "File", then "New",  then click on "C++ Source File" under the "Files" tab.
  2. Make Sure the "Add to Project" box is checked. In the "Filename" box, type in the file's name.
    To keep things simple,  name your file "add1", the .cpp extension is automatically added.
  3. Enter the following is the SystemC code for the 1-bit adder. Enter the code as seen below into the empty file. NOTE: All lines that start with "//" are not needed. These are comments to help you better understand what the actual code is doing.
             // Simulation Tutorial
          // 1-bit Adder
          // This is to include the SystemC constructs and objects.
          #include "systemc.h"
          // We declare the 1-bit ADDER as a "SC_MODULE" with the input and
          // output ports declared immediately after the module declarations
          // This will add two bits together(a,b), with a carry in(cin) and
          // output the sum(sum) and a carry out(cout).
          {       sc_in<sc_logic> a,b,cin;
            sc_out<sc_logic> sum,cout;
    	//In the constructor block of the module, declare a method called "process"
            //with a sensitivity list that includes a, b, & cin.
    SC_CTOR (BIT_ADDER) {      SC_METHOD (process);           sensitive << a << b << cin;        }         //Define the functionality for the "process" method in the 1-BIT adder
    void process()         {              //Declare variables of type "logic" to be used in calculations
         sc_logic aANDb,aXORb,cinANDaXORb;
               //Perform intermediate calculations for the 1-BIT adder
         //Note to read input from a port, one must use the format: ""            aANDb = &;              aXORb = ^;            cinANDaXORb = & aXORb;              //Calculate sum and carry out of the 1-BIT adder
                 sum = aXORb ^;              cout = aANDb | cinANDaXORb;          }        };   //Don't forget the semicolon!

Simulating the design

  1. Download the testbench file and the simulation file. (in Internet Explorer you can right click on the word 'here' and do a 'save target as').
  2. Save the file to your project directory.
  3. Select the Project Menu, choose "Add to Project", and click "Files". Add the testbench and simulation file to your project
  4. Select the Build menu and choose Build "lab1a.exe".
  5. If no errors, Select the Build menu again and this time choose Execute "lab1a.exe".

Creating and testing the 4-bit adder

  1. Create a New Project by following steps 2-4 in the previous "Setting up SystemC" section.
  2. The design should be called adder4.
  3. Download the following files:  vector.cpp, add4_tst.cpp,and add4_main.cpp
  4. Add all of these files to the design and the the model file from your 1-bit adder: add1.cpp.
  5. Note that there are only two test-cases in the testbench file. You have to add FOUR more unique test cases (each of which you need to include the correct 'assert' statement) and update the print() function in your testbench. 
  6. Compile all files, then build and execute your project to simulate the design.
  7. View the simulation to verity that the 4-bit adder functionality is correct.
  8. Show the results of your test-bench to your TA.

What to turn in:
  1. If you have demo'ed the design to your TA, write up a lab report and e-mail it.
  2. Attach your testbench for the 4-bit adder to your e-mail (the other code is not necessary).