- A Logic Circuit Simulation Library in C++





(libLCS Example) XOR logic using continuous assignment


The aim of this example it build and simulate a circuit which is equivalent to an XOR gate for two inputs. We have to build this using only continuous assignments. Let a and b be inputs to our circuit. Let s be the output. Then, the program to to generate s as an XOR function of a and b is as follows.

#include <lcs/bus.h>
#include <lcs/tester.h>
#include <lcs/simul.h>
#include <lcs/changeMonitor.h>

using namespace lcs;

int main(void)
{
    Bus<1> s, a, b;
        
    // Continuous assignment statements to generate
    // the XOR output. The template parameter
    // indicates the assignment delay. We have used
    // 0 delay here.
    s.cass<0>(a^b);
        
    ChangeMonitor<2> input((a,b), "Input");
    ChangeMonitor<1> output(s, "Output");
        
    Tester<2> tester((a,b));
        
    Simulation::setStopTime(500);
    Simulation::start();
}

The output when the above program is compiled and run is as below. See this for information on interpreting the output.

At time: 0,     Input: 00
At time: 0,     Output: 0
At time: 200,   Input: 01
At time: 200,   Output: 1
At time: 300,   Input: 10
At time: 400,   Input: 11
At time: 400,   Output: 0

Copyright © 2006, 2007 Siva Chandra