Circuits-Combinational Logic-Arithmetic Circuits

2023-10-07 22:30

本文主要是介绍Circuits-Combinational Logic-Arithmetic Circuits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 1、Half adder
  • 2、Full adder
  • 3、3-bit binary adder
  • 4、Adder
  • 5、Signed addition overflow
  • 6、100-bit binary adder
  • 7、4-digit BCD adder
  • 参考资料:https://hdlbits.01xz.net/

1、Half adder

Create a half adder. A half adder adds two bits (with no carry-in) and produces a sum and carry-out.

module top_module( input a, b,output cout, sum );assign cout = a & b;assign sum 	= a ^ b;
endmodule

2、Full adder

Create a full adder. A full adder adds three bits (including carry-in) and produces a sum and carry-out.

module top_module( input a, b, cin,output cout, sum );assign cout = (a&b) | (a&cin) | (b&cin);assign sum = a ^ b ^ cin;
endmodule

3、3-bit binary adder

Now that you know how to build a full adder, make 3 instances of it to create a 3-bit binary ripple-carry adder. The adder adds two 3-bit numbers and a carry-in to produce a 3-bit sum and carry out. To encourage you to actually instantiate full adders, also output the carry-out from each full adder in the ripple-carry adder. cout[2] is the final carry-out from the last full adder, and is the carry-out you usually see.

module top_module( input [2:0] a, b,input cin,output [2:0] cout,output [2:0] sum );assign {cout[0],sum[0]} = a[0] + b[0] + cin;assign {cout[1],sum[1]} = a[1] + b[1] + cout[0];assign {cout[2],sum[2]} = a[2] + b[2] + cout[1];
endmodule

4、Adder

在这里插入图片描述

module top_module (input [3:0] x,input [3:0] y, output [4:0] sum);wire cout[2:0];assign {cout[0],sum[0]} 	= 	x[0] + y[0];assign {cout[1],sum[1]} 	= 	x[1] + y[1] + cout[0];assign {cout[2],sum[2]} 	= 	x[2] + y[2] + cout[1];assign {sum[4] ,sum[3]} 	= 	x[3] + y[3] + cout[2];
endmodule

5、Signed addition overflow

Assume that you have two 8-bit 2’s complement numbers, a[7:0] and b[7:0]. These numbers are added to produce s[7:0]. Also compute whether a (signed) overflow has occurred.
A signed overflow occurs when adding two positive numbers produces a negative result, or adding two negative numbers produces a positive result. There are several methods to detect overflow: It could be computed by comparing the signs of the input and output numbers, or derived from the carry-out of bit n and n-1.

a、b分别两个数的符号位,c为运算结果符号位。
当a =b =0(两数同为正),而c=1(结果为负)时,负溢出;
当a =b =1(两数同为负),而c=0(结果为正)时,正溢出.

module top_module (input [7:0] a,input [7:0] b,output [7:0] s,output overflow
); //assign s = a + b;assign overflow = (a[7]&b[7]&(~s[7])) | ((~a[7])&(~b[7])&s[7]);endmodule

6、100-bit binary adder

Create a 100-bit binary adder. The adder adds two 100-bit numbers and a carry-in to produce a 100-bit sum and carry out.

module top_module( input [99:0] a, b,input cin,output cout,output [99:0] sum );assign {cout,sum[99:0]} = a + b + cin;
endmodule

7、4-digit BCD adder

You are provided with a BCD (binary-coded decimal) one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.
module bcd_fadd {
input [3:0] a,
input [3:0] b,
input cin,
output cout,
output [3:0] sum );
Instantiate 4 copies of bcd_fadd to create a 4-digit BCD ripple-carry adder. Your adder should add two 4-digit BCD numbers (packed into 16-bit vectors) and a carry-in to produce a 4-digit sum and carry out.

module top_module( input [15:0] a, b,input cin,output cout,output [15:0] sum );wire [2:0] cinout;bcd_fadd a1 (a[3:0],		b[3:0],		cin,		cinout[0],	sum[3:0]);bcd_fadd a2 (a[7:4],		b[7:4],		cinout[0],	cinout[1],	sum[7:4]);bcd_fadd a3 (a[11:8],		b[11:8],	cinout[1],	cinout[2],	sum[11:8]);bcd_fadd a4 (a[15:12],		b[15:12],	cinout[2],	cout,		sum[15:12]);
endmodule

参考资料:https://hdlbits.01xz.net/

这篇关于Circuits-Combinational Logic-Arithmetic Circuits的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/160861

相关文章

【BNU】40719 Arithmetic Progressions【分块+FFT】

传送门:【BNU】40719 Arithmetic Progressions 题目分析: 用分块+FFT强行AC了这题…… 之前一直TLE……然后改了好久把姿势改的优美点了……终于过了…… 大概思路是:我们考虑分块,假设每一块的大小为S,一共分了B块然后我们分两种情况讨论: 1.第二个数在第i块,第一个数在(1~i-1)块内,第三个数在(i+1~B)块内。 2.至少两个数在同一块内。

逻辑学(Logic)

GPT-4o (OpenAI)  逻辑学是研究论证的原则和标准的学科,主要关注如何正确地推理和论证。从抓取股票日线数据到形成有效的分析,我们可以应用逻辑推理。 逻辑推理步骤: 1. 明确目标:我们要抓取股票的日线数据。 2. 分析需求:确定需要抓取哪些具体数据,比如日期、开盘价、收盘价、最高价、最低价、成交量等。 3. 选择数据来源:确定从哪个平台或网站获取这些数据,比如Yahoo Financ

100.SAP MII功能详解(14)Workbench-Transaction Logic(Repeater)

目录 1.Logic->Repeater 2.演示 配置对象 配置链接 ​编辑 Repeater的使用示例 1.Logic->Repeater         您可以使用此操作循环浏览XML节点集,该节点集由XML文档中属于同一层次级别的任何XML节点组成。中继器操作执行以下操作: 从节点集的第一个成员开始使用来自第一个节点的信息执行任务移动到下一个节点

[ABC369C] Count Arithmetic Subarrays

首先看了下题意 大致题意就是让你在长度为的序列找出所有的等差数列。 -----------------------------------------------------------------------------------------我是分界线 我的思路了,就是先从2开始计算等差数列,从3开始判断,如果是等差数列的话就继续累加,如果不是判断它是否是第一个等差数列,是就直接,如果

04:创建PADS Logic软件逻辑库

1. 打开自带的库文件 2.保留common库,移除其他库文件 3.新建库 5点击封装工具栏 6选择2D线 7添加端点 8点击保存 9打开查看

LeetCode 446. Arithmetic Slices II - Subsequence

一道长得一副dp的样子的dp题。 这道题难度不算特别大,因为看得出来肯定是dp题。因为,一个等差序列里面有好几个小的等差序列。 例如,2 4是一个等差序列,2 4 6是一个等差序列。 所以我们发现等差序列是可以扩展的。 那么就得到了,咱们的转移方程的一部分 dp[i][delta]=dp[j][delta]+1 dp[i][delta] = dp[j][delta] + 1

ABC 362 E - Count Arithmetic Subsequences

原题链接:E - Count Arithmetic Subsequences 题意:给出长度为n的数组,要求找出所有的等差数列,并且按照长度递增输出。 思路:dp,因为是要找出等差数列,并且这题的数据量极小,所以可以考虑设计dp数组,dp[i][j][k][v],i代表当前寻找的等差数列倒数第二项,j代表最后一项,k代表还需要寻找的长度,v代表当前判断的数,dp[i][j][k][v]代表以i

413. Arithmetic Slices 等差数列划分

https://leetcode-cn.com/problems/arithmetic-slices/description/ 思路:题目很冗长,实际上就是找有几个等差数列(长度大于3的).i作为序列头,从0开始到N-3遍历数组,首先找一个最短的等差序列(长度为3),找到后算出间距dist,再以j为序列尾,从i+3开始到N向后扩张,看等差序列是否还存在后续.只要找到一个间距不等于dist,表明在

SQL logic error no such function: fts5

参考自:Stack Overflow 使用 C# 做全文索引的时候,需要自定义中文分词库,所以需要加载 fts5 扩展后,才可以使用 SELECT fts5(?) 语法,否则就会报告如下错误: SQL logic error no such function: fts5 解决方案: using(var connection = new SQLiteConnection(connectSr

lec(logic equivalence check)--cadence 等价性检查工具理解

文章目录 1. lec是独立的,不基于任何指定的综合工具。key point mappingummapped points有三类 formal functional comparison algorithms两种comparison方式 2. setup mode 和 lec mode3. blackboxsetreport 4. unreachable key points设置选项,尽量避