Circuit Simulator Java

He Codes IT
3 min readAug 17, 2022

--

Circuit Simulator Java is an assignment which is designed to give you some experience in C programming. And also increasing your understanding of circuits.

You will be writing a C program to simulate the output of combinational circuits.

Electronic circuit simulation: uses mathematical models to replicate the behaviour of an actual electronic device or circuit. Simulation software allows for the modelling of circuit operation and is an invaluable analysis tool. Wikipedia

Circuit Simulator Java Description Directives

One of the inputs to your program will be a circuit description file that will describe a circuit using
various directives. We will now describe the various directives. The input variables used in the circuit are provided using the INPUTVAR directive. The INPUTVAR directive is followed by the number of input variables and the names of the input variables. All the input variables will be named with capitalized identifiers. An identifier consists of at least one character (A-Z) followed by a series of zero or many characters (A-Z) or digits (0–9).

For example, some identifiers are IN1, IN2, and IN3. An example specification of the inputs for a
circuit with three input variables: IN1, IN2, IN3 is as follows:
INPUTVAR 3 IN1 IN2 IN3

The outputs produced by the circuit are specified using the OUTPUTVAR directive. Moreover, the OUTPUTVAR directive is followed by the number of outputs and the names of the outputs. For example specification of the circuit with output OUT1 is as follows:
OUTPUTVAR 1 OUT1

The circuits used in this assignment will be built using the following building blocks: NOT, AND,
OR, NAND, NOR, XOR, XNOR, DECODER, and MULTIPLEXER. Further, these building blocks can use either the input variables, temporary variables, a boolean ’1’ or a ’0’ as input.

Describing Circuit Simulator Java using the Directives

It is possible to describe any combinational circuit using the above directives. For example, the circuit OUT1 = IN1.IN2 + IN1.IN3 can be described as follows:
INPUTVAR 3 IN1 IN2 IN3
OUTPUTVAR 1 OUT1
AND IN1 IN2 temp1
AND IN1 IN3 temp2
OR temp1 temp2 OUT1

Note that OUT1 is the output variable. IN1, IN2, and IN3 are input variables. temp1 and temp2
are temporary variables.

Here is another example:
INPUTVAR 4 IN1 IN2 IN3 IN4
OUTPUTVAR 1 OUT1
OR IN3 IN4 temp1
AND IN1 IN2 temp2
MULTIPLEXER 4 0 1 0 1 temp2 temp1 OUT1
As seen above, a circuit description is a sequence of directives. If every temporary variable occurs as an output variable in the sequence before occurring as an input variable, we say that the circuit description is sorted. You can assume that the circuit description files will be sorted.

Format of the Input Files

Example Execution 1
Suppose a circuit description file named circuit.txt has the description for the circuit

OUT1 = IN1.IN2 + IN1.IN3
Then the description file is as follows:

5
INPUTVAR 3 IN1 IN2 IN3
OUTPUTVAR 1 OUT1
AND IN1 IN2 temp1
AND IN1 IN3 temp2
OR temp1 temp2 OUT1
2
6
Then, on executing the program with the above circuit description file, your program should produce
the following output (one line for each input).
./first circuit.txt
0
1

Download the Code here https://hecodesit.com/circuit-simulator-java/

--

--

He Codes IT
He Codes IT

Written by He Codes IT

A tech blog for Computer Science Students, offering posts on courses like Databases, Data Structures, Algorithms and Data Science. https://www.hecodesit.com

No responses yet