Brief introduction to circuit simulation using logic-sim

• How to simulate a digital circuit with logic-sim

• Steps:

1. Write a C-function named simnet() (simulation network) that defines the circuit that you want to simulate

This C-function must be stored in a circuit file called:

 ``` circuitFileName.cc ```

2. Compile the circuit using the command:

 ``` cs355sim circuitFileName ```

3. When the compilation is successful, you can run the circuit simulation using this command:

 ``` simex ```

(Simulation execute)

• Example

• We first write the following circuit simulation:

 ```/* ===================================================================== * Always include this header file when writing digital simulation !!! * ===================================================================== */ #include "Sim.h" void simnet() { Sig(sw0,1); // Define sw0 as a signal Sig(sw1,1); // Define sw1 as a signal Sig(out,1); // Define out as a signal Switch ( "aa", sw0, 'a', Zero ); // Location = "aa", name = sw0, key = 'a' Switch ( "ca", sw1, 'b', One ); // Initial value: Zero or One And ( "bb", (sw0,sw1), out ); // And: inputs = (sw0,sw1), output = out // Note: ( .., .. ) group signals into 1 signal // Note: sw0 is equivalent to sw0[0] Probe ( "bc", out ); // Probe out } ```

We save this circuit simulation in a file named and.cc

• Then we compile with this command:

 ``` cs355sim and ```

You will see this message:

 ``` Circuit file(s): and.cc Done Use this command to run the circuit simulation: simex ```

• To run the circuit simulation, execute this command:

 ``` simex ```

and you will see this window:

• You can then interact with the circuit simulation by toggling the state of the switches in the circuit simulation

• Example Program: (Demo above code)

How to run the program:

 Right click on link and save in a scratch directory To compile:   cs355sim and To run:          ./simex