https://mp.weixin.qq.com/s/yJx_dV6ScUStJtPWVuD38w

原理图

参考链接

https://github.com/wjcdx/jchdl/blob/master/src/org/jchdl/model/gsl/example/Mux4.java

1.创建Mux4.java, 并生成构造方法和logic()方法

2. 根据逻辑原理图,添加输入输出线

需要注意的是,这里使用了WireVec,而不是Wire来声明输入线,以便统一处理一排线。

3. 在构造方法中搜集输入输出线并调用construct()方法

这里一次性的把dat, sel中的所有线都加到输入线中。

4. 在logic()方法中创建子节点并连线

创建WireVec时可以直接与input/output相连;使用时从WireVec中取出某一条线使用即可。

这里更通用的做法,是记录输入WireVec dat的位数,这样在logic()取的时候,就不需要把数字写死了:

5. 创建inst静态方法方便后续使用

6. 创建main方法执行验证

运行结果为:

四种组合逐个选择i0~i3中的值。

7. 生成Verilog

执行结果如下:

package vec;

import org.jchdl.model.gsl.core.datatype.helper.WireVec;

import org.jchdl.model.gsl.core.datatype.net.Wire;

import org.jchdl.model.gsl.core.meta.Node;

import org.jchdl.model.gsl.core.meta.PropagateManager;

import org.jchdl.model.gsl.core.value.Value;

import org.jchdl.model.gsl.operator.conditional.Mux;

public class Mux4 extends Node {

private int nDatBits = 0;

private WireVec dat;

private WireVec sel;

private Wire out;

private Wire o0 = new Wire();

private Wire o1 = new Wire();

public Mux4(Wire out, WireVec dat, WireVec sel) {

nDatBits = dat.nBits();

in(dat.wires());

in(sel.wires());

out(out);

construct();

}

@Override

public void logic() {

dat = new WireVec(inputs(0, nDatBits));

sel = new WireVec(inputs(nDatBits));

out = new Wire(out(0));

Mux.inst(o0, dat.wire(0), dat.wire(1), sel.wire(0));

Mux.inst(o1, dat.wire(2), dat.wire(3), sel.wire(0));

Mux.inst(out, o0, o1, sel.wire(1));

}

public static Mux4 inst(Wire out, WireVec dat, WireVec sel) {

return new Mux4(out, dat, sel);

}

public static void main(String[] args) {

WireVec dat = new WireVec(4);

WireVec sel = new WireVec(2);

Wire out = new Wire();

Mux4 mux4 = Mux4.inst(out, dat, sel);

dat.assign(new Value[]{Value.V0, Value.V1, Value.V0, Value.V1});

sel.assign(new Value[]{Value.V0, Value.V0});

PropagateManager.propagateParallel(dat, sel);

System.out.println("out: " + out.getValue().toString());

sel.assign(new Value[]{Value.V1, Value.V0});

PropagateManager.propagateParallel(sel);

System.out.println("out: " + out.getValue().toString());

sel.assign(new Value[]{Value.V0, Value.V1});

PropagateManager.propagateParallel(sel);

System.out.println("out: " + out.getValue().toString());

sel.assign(new Value[]{Value.V1, Value.V1});

PropagateManager.propagateParallel(sel);

System.out.println("out: " + out.getValue().toString());

mux4.toVerilog();

}

}

jchdl - GSL实例 - Mux4(使用WireVec简化输入线声明)的更多相关文章

  1. jchdl - GSL实例 - Mux4

    https://mp.weixin.qq.com/s/hh0eExVFC6cxzpvNI1cA9A 使用门实现四选一选择器. 原理图 ​​ 参考链接 https://github.com/wjcdx/ ...

  2. jchdl - GSL实例 - Mux4(使用Mux)

    https://mp.weixin.qq.com/s/GrYJ4KXEFRoLLmLnAGoMSA 原理图 ​​ 参考链接 https://github.com/wjcdx/jchdl/blob/ma ...

  3. jchdl - GSL实例 - Concat

    https://mp.weixin.qq.com/s/oJY6Xj9_oM1gSmvH_dHkJg   Concat节点把多根输入线线组合成一排线输出.   参考链接 https://github.c ...

  4. jchdl - GSL实例 - Add

    https://mp.weixin.qq.com/s/6xcYYdYZTBPTf25xFluzBQ   使用FullAdder级联实现加法器   参考链接: https://github.com/wj ...

  5. jchdl - GSL实例 - Assign

    https://mp.weixin.qq.com/s/MtHR3iolPd5VQq6AUE-JPg   Assign是一个节点,把输入线直接赋值给输出线.在转换成Verilog时,这种类型的节点会直接 ...

  6. jchdl - GSL实例 - LogicalLeft

    https://mp.weixin.qq.com/s/WNm4bLWzZ0oWHWa7HQ6Y6w   逻辑左移,继承自Shifter类.只需要实现shift方法即可.   参考链接 https:// ...

  7. jchdl - GSL实例 - Shifter

    https://mp.weixin.qq.com/s/ngQji-xi4FCCbL_2ihUi_A   Shifter是移位节点的父类,定义了输入输出线,但是没有定义具体的移位方式,这个留给子类去实现 ...

  8. jchdl - GSL实例 - Sub(二的补码实现)

    https://mp.weixin.qq.com/s/10fgjqPt2pRvIJzjDGYgBg   概念辨析   <IC-二进制, 自然数, 有符号数>:https://mp.weix ...

  9. jchdl - GSL实例:HalfAdder

    https://mp.weixin.qq.com/s/Y97bIro7UlPPFCoPlzgmOQ 半加器电路是指对两个输入相加,输出一个结果位和,没有进位输入的电路. 是实现两个一位二进制数的加法运 ...

随机推荐

  1. 你知道Spring是怎么解析配置类的吗?

    彻底读懂Spring(二)你知道Spring是怎么解析配置类的吗? 推荐阅读: Spring官网阅读系列 彻底读懂Spring(一)读源码,我们可以从第一行读起 Spring执行流程图如下: 如果图片 ...

  2. LeetCode--Unique Morse Code Words && Flipping an Image (Easy)

    804. Unique Morse Code Words (Easy)# International Morse Code defines a standard encoding where each ...

  3. 一文教你快速学会在matlab的simulink中调用C语言进行仿真

    本文介绍如何在matlab的simulink中嵌入C语言进行多输入多输出的仿真:matlab版本位2015b: 创作不易,如果本文帮到了您: 如果本文帮到了您,请帮忙点个赞

  4. Liunx常用操作(五)-如何查询文档中的冒号与引号

    liunx下面有如下一段包含json格式的文档 一.单查所有冒号: .txt | grep [:] 结果如下: 二.单查所有引号: 这里需要转义 .txt | grep [\"] 三.gre ...

  5. Python:日薪工资计算

    劳动者离职,当天要结清工资,实际操作是当天算清,三日内结清.有的公司省人力和吃利息,统一计算,统一下月月底发放. 有时要验算下离职工资,用Python操作一番,输入计时天数.请假小时.加班小时.基本工 ...

  6. ObjectOutputStream:对象的序列化流 ObjectInputStream:对象的反序列化流

    package com.itheima.demo04.ObjectStream; import java.io.FileOutputStream; import java.io.IOException ...

  7. Mysql常用sql语句(21)- regexp 正则表达式查询

    测试必备的Mysql常用sql语句系列 https://www.cnblogs.com/poloyy/category/1683347.html 前言 正则的强大不言而喻,Mysql中也提供了 reg ...

  8. linux-设置代理和取消代理

    设置代理: export http_proxy="http://proxy-XXXXX" export https_proxy="https://proxy-XXXXX: ...

  9. 2020网鼎杯 白虎组reverse:hero

    主函数,当bossexist的值不为0时,while循环dround()函数,循环结束输出flag outflag()函数的flag值由6段数据拼凑而成 while循环的dround()函数有三个选择 ...

  10. git:error: Your local changes to the following files would be overwritten by merge:

    最近用git在服务器.github.本地更新代码的时候,因为频繁修改偶尔出现这个错误 覆盖本地的代码: git stash git pull git stash pop 保留对服务器上的修改: git ...