jchdl - GSL实例 - ComplementTwo(二的补码)

 
二的补码指对二进制数的所有位数整体求补。二进制运算下0,1互为补数,n位二进制数a的补数为2^n - a
 
The two's complement of an N-bit number is defined as its complement with respect to 2N. For instance, for the three-bit number 010, the two's complement is 110, because 010 + 110 = 1000.
Conveniently, another way of finding the two's complement of a number is to take its ones' complement and add one: the sum of a number and its ones' complement is all '1' bits, or 2N − 1; and by definition, the sum of a number and its two's complement is 2N.
 
 
参考链接
 
 
1.创建Sub.java, 并生成构造方法和logic()方法
 
2. 根据逻辑原理图,添加输入输出线
 
3. 在构造方法中搜集输入输出线并调用construct()方法
 
4. 在logic()方法中创建子节点并连线
计算方法:2的补码 = 1的补码 + 1.
 
5. 创建inst静态方法方便后续使用
 
6. 创建main方法执行验证
 
运行结果为:
即-1的补码表示。
 
 
7. 生成Verilog
生成定制化模块名:
 
调用toVerilog()方法生成Verilog实现。
 
执行结果如下:
其余子模块的生成代码略去。
 
 
posted @ 2018-09-26 10:01  wjcdx  阅读(236)  评论(0编辑  收藏  举报