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

原理图

参考链接

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

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

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

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

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

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

6. 创建main方法执行验证

运行结果为:

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

7. 生成Verilog

执行结果如下:

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 Wire i0;

private Wire i1;

private Wire i2;

private Wire i3;

private Wire s1;

private Wire s0;

private Wire out;

private Wire o0 = new Wire();

private Wire o1 = new Wire();

public Mux4(Wire out, Wire i0, Wire i1, Wire i2, Wire i3, Wire s1, Wire s0) {

in(Wire.array(i0, i1, i2, i3, s1, s0));

out(out);

construct();

}

@Override

public void logic() {

i0 = new Wire(in(0));

i1 = new Wire(in(1));

i2 = new Wire(in(2));

i3 = new Wire(in(3));

s1 = new Wire(in(4));

s0 = new Wire(in(5));

out = new Wire(out(0));

Mux.inst(o0, i0, i1, s0);

Mux.inst(o1, i2, i3, s0);

Mux.inst(out, o0, o1, s1);

}

public static Mux4 inst(Wire out, Wire i0, Wire i1, Wire i2, Wire i3, Wire s1, Wire s0) {

return new Mux4(out, i0, i1, i2, i3, s1, s0);

}

public static void main(String[] args) {

Wire i0 = new Wire(Value.V0);

Wire i1 = new Wire(Value.V1);

Wire i2 = new Wire(Value.V0);

Wire i3 = new Wire(Value.V1);

Wire s1 = new Wire(Value.V0);

Wire s0 = new Wire(Value.V0);

Wire out = new Wire();

Mux4 mux4 = Mux4.inst(out, i0, i1, i2, i3, s1, s0);

PropagateManager.propagateParallel(i0, i1, i2, i3, s1, s0);

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

s1.assign(Value.V0);

s0.assign(Value.V1);

PropagateManager.propagateParallel(s1, s0);

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

s1.assign(Value.V1);

s0.assign(Value.V0);

PropagateManager.propagateParallel(s1, s0);

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

s1.assign(Value.V1);

s0.assign(Value.V1);

PropagateManager.propagateParallel(s1, s0);

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

mux4.toVerilog();

}

}

jchdl - GSL实例 - Mux4(使用Mux)的更多相关文章

  1. jchdl - GSL实例 - Mux4(使用WireVec简化输入线声明)

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

  2. jchdl - GSL实例 - Mux4

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

  3. jchdl - GSL实例 - Add

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

  4. jchdl - GSL实例 - DFlipFlop(D触发器)

    https://mp.weixin.qq.com/s/7N3avTxTd2ZUnAcKg4w3Ig   D触发器对边沿敏感,只有当相应的边沿出现时,才会触发D的值传播到输出Q.   ​​ 引自:htt ...

  5. jchdl - GSL实例 - Div

    因为对除法研究不深,这里略去不表.   有兴趣可以参考链接: https://github.com/wjcdx/jchdl/blob/master/src/org/jchdl/model/gsl/op ...

  6. jchdl - GSL实例 - MulC2(有符号数的乘法)

      这里的实现,先把符号位取出来,使用两个正数相乘,然后在把符号加到乘积上.   参考链接 https://github.com/wjcdx/jchdl/blob/master/src/org/jch ...

  7. jchdl - GSL实例 - Mul(无符号数的乘法)

      这里实现最原始的阵列乘法,逐位相乘然后加到一起.   参考链接 https://github.com/wjcdx/jchdl/blob/edcc3e098d4f1cb21677e86e87a114 ...

  8. jchdl - GSL实例 - LogicalLeft

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

  9. jchdl - GSL实例 - Shifter

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

随机推荐

  1. restful 架构风格的curd(增删改查)

    restful架构 概念:REST指的是一组架构约束条件和原则,如果一个架构符合REST的约束条件和原则,就称之为RESTful架构. restful不是一个专门的技术,他是一个规范.规范就是写写代码 ...

  2. quartus II Warning 好的时序是设计出来的,不是约束出来的

    一.Warning (15714): Some pins have incomplete I/O assignments. Refer to the I/O Assignment Warnings r ...

  3. [hdu5445 Food Problem]多重背包

    题意:一堆食物,有价值.空间.数量三种属性,一些卡车,有空间,价格,数量三种属性.求最少的钱(不超过50000)买卡车装下价值大于等于给定价值的食物,食物可以拆开来放. 思路:这题的关键是给定的条件: ...

  4. 浅析常见的 Web 安全预防

    1. CSRF 跨站请求伪造,英文名:Cross-site request forgery CSRF 攻击流程 结合下面这张图说明 CSRF 的攻击流程. 李四在网站 A 注册了用户名,并且登录到了网 ...

  5. 基于 abp vNext 和 .NET Core 开发博客项目 - 数据访问和代码优先

    上一篇文章(https://www.cnblogs.com/meowv/p/12909558.html)完善了项目中的代码,接入了Swagger.本篇主要使用Entity Framework Core ...

  6. HTML标签和属性三

    八.列表 1.列表的作用 让数据有条理的显示,在数据之前添加标识 但是现在页面布局,经常会使用到无序列表 2.列表的组成 ①有序列表 <ol> <li></li> ...

  7. (数据科学学习手札84)基于geopandas的空间数据分析——空间计算篇(上)

    本文示例代码.数据及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在本系列之前的文章中我们主要讨论了g ...

  8. poj3648 2-SAT进阶 记录点拓扑

    Wedding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10556   Accepted: 3220   Specia ...

  9. 计蒜客 - Fantastic Graph

    题目链接:https://nanti.jisuanke.com/t/31447 知识点: 最大流 题目大意: 给定一个二分图,左边有 $N$ 个点,右边有 $M$ 个点,给出 $K$ 条边.问是否能从 ...

  10. Web Scraper——轻量数据爬取利器

    日常学习工作中,我们多多少少都会遇到一些数据爬取的需求,比如说写论文时要收集相关课题下的论文列表,运营活动时收集用户评价,竞品分析时收集友商数据. 当我们着手准备收集数据时,面对低效的复制黏贴工作,一 ...