如何解决电路跟踪算法
我试图编写用于跟踪电子电路的脚本,其中包括AND与OR之类的逻辑门...我想知道我电路的输出信号。 此图显示了这样的电路。
在我的脚本中:
- 每个门都是AND,OR,nor,NAND类的实例
- 类包括允许将门与输入A,B或输出Y连接的方法
- 每个门实例具有唯一的名称
- 每个门的输入为[实例名称] / [A或B],输出为[实例名称] / [Y]
- 有带网的清单
解决方法
您可以均衡电路,以确定门评估的正确顺序。在计算门输出之前,必须知道门的所有输入。
级别化将门分为相同级别的集合。如果已经评估了其先前的等级,则可以计算后续等级。从一开始就知道主输入线和恒定输入的电平最小。
来自Levelized Simulation chapter的伪代码:
Levelize(MyCircuit) {
SET ReadyGates,ReadyNets;
GATE g;
NET n;
ReadyGates = TheEmptySet;
ReadyNets = TheEmptySet;
For all primary inputs n of MyCircuit do
n.level = 0;
For all gates g in the fanout of n do
If all inputs of g have level numbers Then
Add g to ReadyGates;
EndIf
EndFor
EndFor
Repeat for constant one,constant zero signals;
While ReadyGates is not Empty or ReadyNets is not Empty do
If ReadyGates is not Empty Then
Select gate g and remove it from ReadyGates;
MaxLevel = 0;
For each net n which is an input to g do
If n.Level > MaxLevel Then MaxLevel = n.Level;
EndFor
g.Level = MaxLevel + 1;
For each output n of g do
If all driving gates of n have level numbers Then
Add n to ReadyNets
EndIf
EndFor
EndIf
If ReadyNets is not Empty Then
Select Net n and remove it from ReadyNets;
MaxLevel = 0;
For each driving gate g of n do
If g.Level > MaxLevel Then MaxLevel = g.Level;
EndFor
n.Level = MaxLevel;
For gate g in the fanout of n do
If all inputs of g have level numbers Then
Add g to ReadyGates
EndIf
EndFor
EndIf
EndWhile
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。