Chisel3 - Tutorial - FullAdder
https://mp.weixin.qq.com/s/Aye-SrUUuIP6_o67Rlt5OQ
import chisel3._
class FullAdder extends Module {
val io = IO(new Bundle {
val a = Input(UInt(1.W))
val b = Input(UInt(1.W))
val cin = Input(UInt(1.W))
val sum = Output(UInt(1.W))
val cout = Output(UInt(1.W))
})
// Generate the sum
val a_xor_b = io.a ^ io.b
io.sum := a_xor_b ^ io.cin
// Generate the carry
val a_and_b = io.a & io.b
val b_and_cin = io.b & io.cin
val a_and_cin = io.a & io.cin
io.cout := a_and_b | b_and_cin | a_and_cin
}
object Main {
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array("--target-dir", "generated/FullAdder"), () => new FullAdder)
// chisel3.Driver.execute(args, () => new FullAdder)
}
}
import chisel3.iotesters.{PeekPokeTester, Driver, ChiselFlatSpec}
class FullAdderTester(c: FullAdder) extends PeekPokeTester(c) {
for (t <- 0 until 4) {
val a = rnd.nextInt(2)
val b = rnd.nextInt(2)
val cin = rnd.nextInt(2)
val res = a + b + cin
val sum = res & 1
val cout = (res >> 1) & 1
poke(c.io.a, a)
poke(c.io.b, b)
poke(c.io.cin, cin)
step(1)
expect(c.io.sum, sum)
expect(c.io.cout, cout)
}
}
object FullAdderTester {
def main(args: Array[String]): Unit = {
chisel3.iotesters.Driver(() => new FullAdder)(c => new FullAdderTester(c))
}
}
Chisel3 - Tutorial - FullAdder的更多相关文章
- Chisel3 - Tutorial - Adder
https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A 位数为参数的加法器.通过FullAdder级联实现. 参考链接: https://githu ...
- Chisel3 - Tutorial - Adder4
https://mp.weixin.qq.com/s/X5EStKor2DU0-vS_wIO-fg 四位加法器.通过FullAdder级联实现. 参考链接: https://github.co ...
- Chisel3 - Tutorial - VendingMachine
https://mp.weixin.qq.com/s/tDpUe9yhwC-2c1VqisFzMw 演示如何使用状态机. 参考链接: https://github.com/ucb-bar/ch ...
- Chisel3 - Tutorial - VendingMachineSwitch
https://mp.weixin.qq.com/s/5lcMkenM2zTy-pYOXfRjyA 演示如何使用switch/is来实现状态机. 参考链接: https://github.co ...
- Chisel3 - Tutorial - Tbl
https://mp.weixin.qq.com/s/e8vJ8claauBtiuedxYYaJw 实现可以动态索引的表. 参考链接: https://github.com/ucb-bar/c ...
- Chisel3 - Tutorial - Stack
https://mp.weixin.qq.com/s/-AVJD1IfvNIJhmZM40DemA 实现后入先出(last in, first out)的栈. 参考链接: https://gi ...
- Chisel3 - Tutorial - Functionality
https://mp.weixin.qq.com/s/3hDzpJiANdwp07hO03psyA 演示使用函数进行代码复用的方法. 参考链接: https://github.com/ucb- ...
- Chisel3 - Tutorial - Parity
https://mp.weixin.qq.com/s/OtiQnE52PwdCpvmzJ6VFnA 奇偶发生器.统计输入中1的个数,如果为偶数则输出0,奇数则输出1. 参考链接: https: ...
- Chisel3 - Tutorial - ByteSelector
https://mp.weixin.qq.com/s/RQg2ca1rwfVHx_QG-IOV-w 字节选择器. 参考链接: https://github.com/ucb-bar/chisel ...
随机推荐
- IDEA中如何使用debug调试项目 一步一步详细教程
转载该文章:https://blog.csdn.net/yxl_1207/article/details/80973622 一.Debug开篇 首先看下IDEA中Debug模式下的界面. 如下是在ID ...
- C# 数据操作系列 - 0. 序言
0. 前言 在上一个系列中,我们初步浏览了一下C#的基础知识.这句话的意思就是C#基础知识系列完结了,撒花.当然,并不是因为C#已经讲完了.正是因为我们轻轻地叩开了那扇门,才能看到门后面那瑰丽的世界. ...
- Json格式数据的解析
JSON是一种轻量级的数据交换格式,我们在编程中遇到的JSON数据通常就是一串字符串,只不过按照特定的格式去书写,这样当你把JSON数据传输给别人的时候对方只要使用这种特定的规则去阅读解析你的数据即可 ...
- 【Hadoop离线基础总结】Hue与Hadoop集成
目录 1.更改所有hadoop节点的core-site.xml配置 2.更改所有hadoop节点的hdfs-site.xml 3.重启hadoop集群 4.停止hue的服务,并继续配置hue.ini ...
- Ubuntu 配置/etc/fstab参数实现开机自动挂载硬盘
文章目录 前言 fstab 参数含义 实现步骤 1 查看硬盘信息,并找到需要进行挂载的硬盘 2 sudo mkfs.ext4 /dev/sdc 3 sudo mkdir /home/diska 4 查 ...
- 设计模式GOF23之单例模式
单例模式的五种方式 主要:懒汉式,饿汉式 其他:双重检测锁(Double Checking模式),静态内部类,枚举模式 选取时机 延时加载,占用内部资源大:静态内部类好于懒汉 不延时加载,占用内部资源 ...
- [hdu5313]二分图性质,dp
题意:给定二分图,求添加的最多边数,使得添加之后还是二分图 思路:如果原图可以分成X,Y两个点集,那么边数最多为|X||Y|条.由于|X|+|Y|==n,所以需要使|X|与|Y|尽量接近.先对原图进行 ...
- HDU 2001 (水)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2001 题目大意:两个点求距离 解题思路: 套基本公式 a = √(b2 + c2); 小数点后几位的表 ...
- Mysql 常用函数(6)- replace 函数
Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html replace 的作用 将某些字符串替换成新的字符 ...
- python爬虫-直播吧
概述 这是一个我很喜欢的小网站,想了解这个网站先从爬虫开始,爬取直播吧所有的栏目及内容,再存入数据库.先写个简单点的,后期再不断的优化下. 准备阶段 直播吧网址https://www.zhibo8.c ...