Chisel3 - Tutorial - Adder
https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A
- import chisel3._
- //A n-bit adder with carry in and carry out
- class Adder(val n:Int) extends Module {
- val io = IO(new Bundle {
- val A = Input(UInt(n.W))
- val B = Input(UInt(n.W))
- val Cin = Input(UInt(1.W))
- val Sum = Output(UInt(n.W))
- val Cout = Output(UInt(1.W))
- })
- //create an Array of FullAdders
- // NOTE: Since we do all the wiring during elaboration and not at run-time,
- // i.e., we don't need to dynamically index into the data structure at run-time,
- // we use an Array instead of a Vec.
- val FAs = Array.fill(n)(Module(new FullAdder()).io)
- // val FAs = Array.fill(n)(Module(new FullAdder()))
- val carry = Wire(Vec(n+1, UInt(1.W)))
- val sum = Wire(Vec(n, Bool()))
- //first carry is the top level carry in
- carry(0) := io.Cin
- //wire up the ports of the full adders
- for (i <- 0 until n) {
- FAs(i).a := io.A(i)
- FAs(i).a := io.A(i)
- FAs(i).b := io.B(i)
- FAs(i).cin := carry(i)
- carry(i+1) := FAs(i).cout
- sum(i) := FAs(i).sum.toBool()
- }
- // for (i <- 0 until n) {
- // FAs(i).io.a := io.A(i)
- // FAs(i).io.a := io.A(i)
- // FAs(i).io.b := io.B(i)
- // FAs(i).io.cin := carry(i)
- // carry(i+1) := FAs(i).io.cout
- // sum(i) := FAs(i).io.sum.toBool()
- // }
- io.Sum := sum.asUInt
- io.Cout := carry(n)
- }
- object AdderMain {
- def main(args: Array[String]): Unit = {
- chisel3.Driver.execute(Array("--target-dir", "generated/Adder"), () => new Adder(4))
- }
- }
Chisel3 - Tutorial - Adder的更多相关文章
- 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 ...
- Chisel3 - Tutorial - ShiftRegister
https://mp.weixin.qq.com/s/LKiXUgSnt3DzgFLa9zLCmQ 简单的寄存器在时钟的驱动下,逐个往下传值. 参考链接: https://github.com ...
随机推荐
- Matlab矩阵总结
- Spring Cloud feign GET请求无法用实体传参的解决方法
代码如下: @FeignClient(name = "eureka-client", fallbackFactory = FallBack.class, decode404 = t ...
- MySQL连接不上
access denied for user root @localhost 解决办法: create user 'root'@'localhost' identified by '你的密码'; gr ...
- 004_Python的列表切片,增删改查,常用操作方法,元组,range,join
列表 列表是Python中的基础数据类型之一,它是以[]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如: li = ['kevin',123,True,(1,2,3,'wusir'), ...
- Polar码快速入门
Polar码快速入门 本科生在学习极化码时,并不是件简单的事情.网上极化码的资料很少,而且基本上都是较难的论文.这篇文章是用来帮你快速入门极化码. Poalr码背景 2015 年,国际电信联盟无线通信 ...
- 一文教你如何在ubuntu上快速搭建STM32 CubeIDE环境(图文超详细+文末有附件)
在快速ubuntu上安装cubeide你值得拥有:适合对linux系统还不是很熟悉的同学: 文章目录 1 下载 cubeide 2 找到软件 3 安装 4 附件 5 总结 1 下载 cubeide 登 ...
- 学习python的第一天,python的简单知识
python 是现如今比较火的一种编程语言.在抱着试试的态度我来进行学习下python.要学习python 要先进行环境的安装. 下面是下载链接:https://pan.baidu.com/s/1PW ...
- 小心了!Kubernetes自动化操作工具将让你失去工作
运行Kubernetes的人已经花费太多时间在操作上,企业正在考虑为Kubernetes编写自动化工具. 尽管IT部门的大部分职位都会增加,但职业顾问说,计算机操作员预计会减少.这个角色涉及运行She ...
- 一、线程 & 线程池
一.线程的介绍 1.1.概念 进程: 你的硬盘上有一个简单的程序,这个程序叫QQ.exe,这是一个程序,这个程序是一个静态的概念,它被扔在硬盘上也没人理他,但是当你双击它,弹出一个界面输入账号密码登录 ...
- mybatis中 #{} 和 ${}
在mybatis中#{}表示一个占位符: 1.#将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号 2.#在很大程度上可以防止sql注入 3.例如#{id}:#{}中的id表示输入的参数名称 ...