Uploaded by Oscar Fernando Araya Garbanzo

Combinational logic circuit solving using recursive programming

advertisement
See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/351335327
Combinational logic circuit solving using recursive programming
Research · May 2021
DOI: 10.13140/RG.2.2.29749.81123
CITATIONS
READS
0
720
1 author:
Oscar Araya Garbanzo
Costa Rican Institute of Technology (ITCR)
1 PUBLICATION 0 CITATIONS
SEE PROFILE
All content following this page was uploaded by Oscar Araya Garbanzo on 04 May 2021.
The user has requested enhancement of the downloaded file.
Combinational logic circuit solving using recursive
programming
Oscar Araya Garbanzo
Computer Engineering Academic Area
Costa Rican Institute of Technology
Cartago, Costa Rica
osaronaragar15@gmail.com
Abstract—Combinational logic circuits are the basic unit for
the construction of digital systems. Although there are tools
that allow solving these circuits, they do not provide developers,
students and teachers with a clear view of the algorithms that
operate behind the simulation. In this paper, a method for
solving combinational logic circuits by implementing a recursive
algorithm is provided. This solution is focused on the objectoriented paradigm, and is developed in the Java programming
language. Although it has been devised to comply with the
syntax and good practices of this language, its foundation can be
extrapolated to different paradigms and languages that support
recursion as a problem-solving technique. This document is
limited to detailing the bases on which more complex digital
circuit solving algorithms can be built (for example, considering
sequential logic or analog electronics components). However, and
cutting a little the scope of this research, we will only focus on
combinational logic, with the use of logic gates such as AND, OR,
NOT or XOR. After the development of this algorithm, it was
concluded that, in a few lines of code, it is possible to express the
operation, interaction and correlation of the different electronic
elements that compose the combinational logic.
I. I NTRODUCTION
a remainder that is an easier version of the same problem. We
can then repeat this process, taking the same step towards the
solution each time, until we reach a version of our problem
with a very simple solution (referred to as a base case) [1].
B. Combinational logic circuits, a recursive approach.
At any time, a combinational logic circuit’s output (or
outputs), depends only upon the combination of its inputs
at that time. The important point is that the output is not
influenced by previous inputs, or in other words the circuit has
no memory [2]. This property of combinational logic circuits
seems to make their solution procedure a perfect candidate for
the use of recursive programming.
Combinational logic circuits, in their most basic state, are
composed of three fundamental elements: input terminals with
a binary logic value (1 or 0), output terminals where the
resulting logic value will be measured, and logic gates, which
are nothing more than an abstraction of groups of transistors
that operate a certain logic function, dependent on the input
voltages of the electronic component in question.
A. Recursive programming as a problem-solving method.
Recursion is a powerful tool that gives programmers the
ability to solve problems that require indefinite repetition of
”steps”. As a classic example, we have the definition of the
Fibonacci sequence, which can be expressed from its very
definition by operating with natural numbers.
f0 = 0
f1 = 0
(1)
fn = fn−1 + fn−2
Fig. 1: Combinational logic circuit with two input terminals
(δ and ) and one output terminal (A).
As detailed in equation (1), and as a general rule for all
recursive algorithms, there is a problem involving an indefinite
number of n terms, and more importantly, this problem has a
stop condition (also called base case), where the recursion
stops computing from other terms of its own definition. In the
case of equation (1), this occurs when the Fibonacci sequence
is computed for either one or zero, the result of which, by
definition, is zero.
In general, with recursion we try to break down a more
complex problem into a simple step towards the solution and
Let’s analyze for a moment the circuit shown in figure 1.
The output terminal is represented by the light bulb connected
to wire A. In case the output of the circuit is a logic 1, the
light bulb turns on, as is the case in the picture. Otherwise, if
the output of the circuit is a logic 0, the light bulb will remain
off. The input terminals are represented by the Greek letters
δ (logic 0) and (logic 1).
By focusing the solution process from the output terminals
to the inputs (i.e. starting from wire A to the input terminals δ
and in figure 1), it is possible to define a recursive solution
algorithm, which runs through the circuit until the logic value
of each wire connecting the electronic components is obtained.
This solution algorithm can be broken down into the following steps:
1) Find the desired output terminal (wire A in figure 1).
2) Find the logic gate that generates the specific output of
this terminal (OR gate α in figure 1).
3) It is necessary to find the logical value of each of the
inputs of this gate, to operate them later in the specific
function of the gate and generate that gate output. For
this, for each wire that connects to its input terminals,
the following is done:
• If the electronic component to which it is connected
is an input terminal, the logical value of the same
is returned.
• If the electronic component to which it is connected
is a logic gate, step 3 is repeated with this logic gate
found in this point.
Note that, within step three of the algorithm, two possible solution alternatives are contemplated once the desired
measurement terminal, and the gate that generates its logical
state, have been found. First, it must be checked if the inputs
are gates. If they are, the solution process must be repeated
recursively until the logical expression of an input terminal is
found, which allows the logical functions of the gates involved
to be performed. This case, that of ”encountering” an input
terminal with a defined logic value, will be our stop condition
within the recursive algorithm.
The logicFunctionID attribute is used to establish a relationship between the created component and a specific logic
function. Since every electronic component is treated as a gate,
even the input and output terminals have their own identifier.
The codes used are detailed below:
0) Input low terminal (logic 0).
1) Input high terminal (logic 1).
2) Output terminal.
3) BUFFER gate.
4) NOT gate.
5) AND gate.
6) OR gate.
7) XOR gate.
8) NAND gate.
9) NOR gate.
10) XNOR gate.
The list of gates at the input, inGates, can have a size n,
with the exception of BUFFER or AND type gates, which,
by definition of combinational logic, can only have one input
terminal.
2) BuiltinLogicFunctions: this class is in charge of storing
in the code all the logical functions that objects of type Gate
can have, based on its logicFunctionID attribute. This class has
a method that returns a boolean value for each type of logic
function. For gates that can receive n inputs, these methods
receive a list called inputs, which is operated under the criteria
of each of the logic functions defined by combinational logic.
II. M ETHODOLOGY
Having clear the scheme of operation of the solution algorithm, it is time to start with the coding process, using the Java
programming language, version 11. The code will be written
under a traditional object-oriented approach.
A. Class definition.
1) Gate: for this algorithm, every electronic component is
considered a logic gate. Its logic function depends on the int
type attribute logicFunctionID. Its other attribute, inGates, is
a dynamic list of Gate type elements, which contains the logic
gates that are connected to its input terminals.
Fig. 3: BuiltinLogicFunctions class code, showing the operation of the logical functions BUFFER, NOT and AND.
Fig. 2: Gate class code.
3) Main: this is the class from which the combinational circuit will be solved by executing the algorithm. It is composed
of the traditional main method, typical of all Java programs,
the solveCircuit method, which takes all the output terminals
belonging to the outGates list and finds their value, and
the algorithm, called findSolvingPath, which will be detailed
below.
B. findSolvingPath algorithm.
This is the algorithm in charge of the resolution of combinational logic circuits. Its code was written considering the
steps established in the Introduction section.
It works by making recursive calls to itself, passing as
recursion parameter a currentGate object of type Gate. Each
recursive call tries to determine whether the logical value of
that currentGate owns, based on the following assumptions:
1) If currentGate.logicFunctionID is 0, a stop condition is
reached, where the logic value 0 is returned.
2) If currentGate.logicFunctionID is 1, a stop condition is
reached, where the logic value is 1 is returned.
3) If currentGate.logicFunctionID is 2, the recursive call of
the algorithm is returned, with the new currentGate being the only input terminal that the current currentGate
can have (since it is an output terminal).
4) If currentGate.logicFunctionID is 3, the gate is a
BUFFER, so the BUFFER logic function of the BuiltinLogicFunctions class is returned, which receives as
parameter the recursive call of the algorithm, with the
new currentGate being the only input terminal that the
current currentGate can have (being a BUFFER gate).
5) If currentGate.logicFunctionID is 4, the gate is a NOT,
so the NOT logic function of the BuiltinLogicFunctions
class is returned, which receives as parameter the recursive call of the algorithm, with the new currentGate
being the only input terminal that the current currentGate can have (being a NOT gate).
6) If currentGate.logicFunctionID is any other of the codes
specified for logicFunctionID, an iteration is made over
all the inputs of the currentGate, adding to a boolean
type list of inputs all the values returned by the recursive
call to the algorithm with each of the inputs of this
iteration over the inputs of the currentGate. Finally,
when the solution of this list of inputs has been found,
the type of gate is evaluated, according to the logicFunctionID code, and the corresponding function within
BuiltinLogicFunctions is called, passing as parameter the
list of inputs.
Fig. 6: Main class code.
Fig. 7: findSolvingPath algorithm code.
Fig. 4: BuiltinLogicFunctions class code, showing the operation of the logical functions OR, XOR and NAND.
Fig. 5: BuiltinLogicFunctions class code, showing the operation of the logical functions NOR and XNOR.
C. findSolvingPath algorithm usage.
Once it is understood how the findSolvingPath algorithm
works, it is time to implement it for solving a combinational
logic circuit.
Fig. 8: Combinational logic circuit to be calculated using the
findSolvingPath algorithm.
Once the schematic of the combinational logic circuit to be
solved is clear, it is possible to code an abstraction using the
classes defined above.
Fig. 11: Creation of inGates attributes, part 2.
Fig. 12: Call to the solution algorithm, with the list of
outTerminals output terminals.
Fig. 9: Creation of all Gate type objects. Its inGates attribute
is initialized as null, to be later modified.
Figures 9, 10, 11 and 12 represent the basic use of the
findSolvingPath algorithm. Clearly, there are more optimal and
simpler methods for the definition of the combinational logic
circuit, such as simplification by Boolean algebra or reuse of
input terminals. However, the exercise presented here provides
a clear view of the process of solving a combinational logic
problem.
The execution of the code presented in Figures 9,10, 11 and
12, gives the expected result of out1 as logic 1, and out2 as
logic 0, shown in Figure 8..
III. D ISCUSSION
Fig. 10: Creation of inGates attributes, part 1.
The development of the findSolvingPath algorithm provides
a viable and simple alternative for solving combinational logic
circuits. It has been demonstrated that, in a few lines of code,
it is possible to define a recursive process capable of traversing
an abstraction of a digital circuit.
As alternatives to this algorithm, an iterative process could
be considered, using while or for statements. However, the
inherent ease intrinsic to recursion, by using its very definition
for its resolution process, makes recursion an ideal tool for the
problem at hand.
The scope of this paper has been limited to show the
algorithm, its theoretical foundation and its use. It is left to
the reader, or to future research on my part, to improve its
scalability and efficiency.
IV. C ONCLUSION
From the execution of the present investigation, it is concluded that:
1) Combinational logic circuits can be solved based on
a series of sequential steps, based on the electronic
components used, and their logical behavior.
2) It should be considered that the scalability of the solution
algorithm is not optimal, since it requires an intensive
use of object instantiation.
3) Combinational logic circuits can be interpreted as a
recursive problem, since the output of each gate depends
on its input terminals, which in turn may depend on
other gates. This dependence can be extended indefinitely.
R EFERENCES
[1] T. Grigg, ”Recursive Programming”, Medium, 2019. [Online].
Available: https://towardsdatascience.com/finding-a-recursive-solution184784b0aea0. [Accessed: 04- May- 2021].
[2] J. Crowe and B. Hayes-Gill, Introduction to digital electronics. Amsterdam: Elsevier Newnes, 1998, p. 46.
View publication stats
Download