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 ...
随机推荐
- 教你配置windows上的windbg,linux上的lldb,打入clr内部这一篇就够了
一:背景 1. 讲故事 前几天公众号里有位兄弟看了几篇文章之后,也准备用windbg试试看,结果这一配就花了好几天,(づ╥﹏╥)づ,我想也有很多跃跃欲试的朋友在配置的时候肯定会遇到这样和那样的问题,所 ...
- 第五章:深入Python的dict和set
第五章:深入Python的dict和set 课程:Python3高级核心技术 5.1 dict的abc继承关系 class Mapping(Collection): __slots__ = () &q ...
- DoNet:浅淡对delegate的理解
1 前言 C#的相关文档,MSDN上其实已经很详细了,关于delegate的使用可以参 考MSDN上的文档https://msdn.microsoft.com/zh-cn/library/900fyy ...
- IE浏览器下报错: strict 模式下不允许一个属性有多个定义
vue项目,打包后在IE11和360浏览器(都是IE内核)上运行,控制台报了strict 模式下不允许一个属性有多个定义这个错误,导致流程不能正常走下去,查资料后知道应该是定义了重复的属性,于是就开始 ...
- 利用Asp.net和Sql Server实现留言板功能
本教程设及到:使用SQL Server查询分析器创建数据库:SQL查询语句常用的一些属性值:触发器创建和使用:存储过程的创建,ASP使用存储过程. 正文: 一.创建数据库: 创建一个feedback数 ...
- [csu/coj 1632]LCP
题意:求一个串的出现次数超过1次的字串的个数 思路:对于一个后缀,出现在它后面的所有后缀与它的LCP的最大值就是应该增加的答案,当然这里没有考虑去重,但是却转化了问题,使得我们可以用最长公共前缀来统计 ...
- Jetson AGX Xavier/Ubuntu安装SSD
参考 https://blog.csdn.net/xingdou520/article/details/84309155 1. 查看硬盘所有分区 sudo fdisk -lu 会找到/dev/nvme ...
- Mysql 常用函数(12)- left 函数
Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html left 的作用 返回字符串 str 中最左边的 ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来
上一篇文章(https://www.cnblogs.com/meowv/p/12896177.html)已经成功创建了博客项目,但是abp默认给我们引用了许多项目中用不到的组件. 本篇文章将给项目进行 ...
- 关于Nginx参数路径问题的问题
本文转载自:https://pureage.info/2013/10/31/130.html 由于工作需要,开始分析nginx的proxy模块,在分析之前,当然要先会用了.于是开始熟悉该模块的一些指令 ...