https://mp.weixin.qq.com/s/6xcYYdYZTBPTf25xFluzBQ
 
使用FullAdder级联实现加法器
 
参考链接:
https://github.com/wjcdx/jchdl/blob/master/src/org/jchdl/model/gsl/operator/arithmetic/Add.java
 
 
1.创建Add.java, 并生成构造方法和logic()方法
 
根据逻辑原理图,添加输入输出线
 
 
3. 在构造方法中搜集输入输出线并调用construct()方法
 
4. 在logic()方法中创建子节点并连线
 
这里首先从input ports牵出线,并创建连接到output ports的线。其中,最后一个input port使用in(-1)取出。最后一个output port使用out(-1)取出。
 
cout作为一个游标,逐次指向每一级的进位线进行连接。最开始为cin,第一级之后代表这一级FullAdder的进位线...直到最后,代表最后一个进位线连接到Add节点的最后一个output port.
 
5. 创建inst静态方法方便后续使用
 
6. 创建main方法执行验证
 
 
运行结果为:
 
 
 
7. 生成Verilog
 
执行结果如下:
 
这样就可以把不同位宽的Add模块区分开来。
需要覆盖getName()方法:
 
原子节点需要覆盖primitive()方法,以返回原语的名称。比如与门,需要返回and:
 
 
更多实例请参考如下链接:
https://github.com/wjcdx/jchdl/tree/master/src/org/jchdl/model/gsl/operator
 
org.jchdl.model.gsl.operator.arithmetic;
 
org.jchdl.model.gsl.core.datatype.helper.WireVec;
org.jchdl.model.gsl.core.datatype.net.Wire;
org.jchdl.model.gsl.core.meta.Node;
org.jchdl.model.gsl.core.value.Value;
 
// treat operands as plain bits
Node {
;
 
;
;
;
;
;
 
Add(WireVec sum, Wire cout, WireVec in1, WireVec in2, Wire cin) {
= in1.nBits();
in(in1.wires());
in(in2.wires());
in(cin);
out(sum.wires());
out(cout);
construct();
}
 
@Override
logic() {
));
));
));
 
));
 
;
; i++) {
Wire();
);
= coutNext;
}
));
}
 
@Override
String getName() {
;
}
 
Add inst(WireVec sum, Wire cout, WireVec in1, WireVec in2, Wire cin) {
Add(sum, cout, in1, in2, cin);
}
 
main(String args[]) {
);
);
);
Wire();
Wire();
 
(out, cout, in1, in2, cin);
 
//0b0000_0010
,
,
});
// 0b1111_1111
,
,
});
);
 
in1.propagate();
in2.propagate();
cin.propagate();
 
+ out);
 
(out, cout, in1, in2, cin).toVerilog();
}
}
 
 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案