基本完成加减法器实验设计
This commit is contained in:
parent
04d283fbb4
commit
68a30caea2
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 44 KiB |
|
@ -0,0 +1,72 @@
|
|||
# 加减法器
|
||||
|
||||
## 一、实验介绍
|
||||
|
||||
加减法器(Adder/Subtractor)是一种用于执行加法和减法运算的部件。它可以根据输入信号的控制来确定是执行加法还是减法操作。
|
||||
|
||||
在加法模式下,加减法器将两个输入数相加,并输出它们的和。加法器通常由多个加法位组成,每个加法位负责处理对应位上的相加运算,并生成该位的和值和进位信号。进位信号作为下一位相加运算的输入。
|
||||
|
||||
在减法模式下,加减法器将一个输入数减去另一个输入数,并输出它们的差。减法操作可以通过将减数取反(取反码)并加 1 来实现。因此,减法器通常包含一个取反器(或称为“反相器”)用于取反减数,并将结果输入到一个加法器中进行相加运算。
|
||||
|
||||
加减法器可以通过控制信号来选择加法或减法模式。通常使用一个控制位,称为"Borrow"或"Subtract",来切换加减法模式。当"Borrow"或"Subtract"位为 0 时,加减法器处于加法模式;当该位为 1 时,加减法器处于减法模式。
|
||||
|
||||
加减法器在数字电路和计算机系统中广泛应用,是实现算术运算的基本组件。它们在处理器、算术逻辑单元(ALU)、计算器和其他数值处理应用中扮演着重要的角色。
|
||||
|
||||
## 二、实验目的
|
||||
|
||||
1. 理解加减法器的原理和功能。
|
||||
2. 学会使用 Verilog 描述加减法器的行为。
|
||||
3. 掌握 Verilog 仿真工具的使用,验证加减法器的正确性。
|
||||
|
||||
## 三、实验要求
|
||||
|
||||
1. 使用 Verilog 描述加减法器的行为。
|
||||
2. 通过所有测试点。
|
||||
|
||||
## 四、实验步骤
|
||||
|
||||
下面以一个 4 位二进制的加减法器为例子:
|
||||
|
||||
### 1. 框图
|
||||
|
||||

|
||||
|
||||
- $A$ 、$B$ 是两个 4 位二进制数的输入端,$Y$ 是输出端为计算结果。
|
||||
- $Cin$ 表示最低位的进位输入,$Cout$是最高位的进位输出。
|
||||
- $\overline{Add}/Sub$ 是加减法器的模式选择端口,当输入 0 时为加法运算,输入 1 时为减法运算。
|
||||
- $ZF\left (ZeroFlag\right)$是零标志,当运算结果$Y$为 0 时,$ZF$输出 1;反之为 0。
|
||||
- $CF\left(CarryFlag\right)$是进位/标志,$CF$有两个含义:
|
||||
- 当进行加法运算时,当作进位标志,表明无符号运算发生溢出。此时若$Cout=1$,则$CF=1$;若$Cout=0$,则$CF=0$。
|
||||
- 当进行减法运算时,当作借位标志,表明不够减。此时若$Cout=1$,则$CF=0$;若$Cout=0$,则$CF=1$。
|
||||
|
||||
### 2. 顶层模块
|
||||
|
||||
```verilog
|
||||
module Adder_Subtractor(
|
||||
input [3: 0] A,
|
||||
input [3: 0] B,
|
||||
input Cin,
|
||||
input Mode,
|
||||
output [3: 0] Y,
|
||||
output Cout,
|
||||
output ZF,
|
||||
output CF
|
||||
);
|
||||
|
||||
// TODO: 你的代码实现
|
||||
|
||||
endmodule
|
||||
|
||||
```
|
||||
|
||||
在上述代码中,顶层模块名为`Adder_Subtractor`,它有八个端口:
|
||||
|
||||
- $A$ 、$B$ 是两个 4 位二进制数的输入端,$Y$ 是输出端为计算结果。
|
||||
- $Cin$ 表示最低位的进位输入,$Cout$是最高位的进位输出。
|
||||
- $Mode$是加减法器的模式选择端口,当输入 0 时为加法运算,输入 1 时为减法运算。
|
||||
- $ZF\left (ZeroFlag\right)$是零标志,当运算结果$Y$为 0 时,$ZF$输出 1;反之为 0。
|
||||
- $CF\left(CarryFlag\right)$是进位/标志,$CF$有两个含义:
|
||||
- 当进行加法运算时,当作进位标志,表明无符号运算发生溢出。此时若$Cout=1$,则$CF=1$;若$Cout=0$,则$CF=0$。
|
||||
- 当进行减法运算时,当作借位标志,表明不够减。此时若$Cout=1$,则$CF=0$;若$Cout=0$,则$CF=1$。
|
||||
|
||||
请补充代码,完成 4 位二进制加减法器的设计。
|
|
@ -1,3 +1,5 @@
|
|||
# 标题
|
||||
|
||||
## 一、实验介绍
|
||||
|
||||
## 二、实验目的
|
||||
|
@ -11,3 +13,7 @@
|
|||
### 2. 真值表
|
||||
|
||||
### 3. 顶层模块
|
||||
|
||||
在上述代码中,顶层模块名为 `Adder_Subtractor`,它有八个端口:
|
||||
|
||||
请补充代码,完成 4 位二进制加减法器的设计。
|
||||
|
|
|
@ -595,4 +595,82 @@
|
|||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
<diagram id="X1Z5Mt0qpq97yQyyeKMR" name="加减法器">
|
||||
<mxGraphModel dx="696" dy="571" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="1" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-3" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0;exitY=0.25;exitDx=0;exitDy=0;fontColor=default;endArrow=block;endFill=1;strokeWidth=3;rounded=0;" parent="1" source="U6ciwknIUaB1TWmNj2xK-2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="220" y="298" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;strokeWidth=3;fontColor=default;endArrow=block;endFill=1;" parent="1" source="U6ciwknIUaB1TWmNj2xK-2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="220" y="335.1428571428571" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;strokeWidth=3;fontColor=default;endArrow=block;endFill=1;" parent="1" source="U6ciwknIUaB1TWmNj2xK-2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="220" y="372.28571428571433" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.25;exitDx=0;exitDy=0;strokeWidth=3;fontColor=default;endArrow=none;endFill=0;startArrow=block;startFill=1;" parent="1" source="U6ciwknIUaB1TWmNj2xK-2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="570" y="297.42857142857144" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-7" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.75;exitDx=0;exitDy=0;strokeWidth=3;fontColor=default;endArrow=none;endFill=0;startArrow=block;startFill=1;" parent="1" source="U6ciwknIUaB1TWmNj2xK-2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="570" y="372.28571428571433" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-2" value="<span style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-align: left; background-color: rgb(255, 255, 255);">Adder</span><span style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-align: left; background-color: rgb(255, 255, 255);">/Subtracter</span>" style="whiteSpace=wrap;html=1;aspect=fixed;fontStyle=1;fontColor=default;strokeWidth=4;" parent="1" vertex="1">
|
||||
<mxGeometry x="320" y="260" width="150" height="150" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-9" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeWidth=3;fontColor=default;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="395" y="262" as="sourcePoint"/>
|
||||
<mxPoint x="395" y="182" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-10" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeWidth=3;fontColor=default;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="370" y="490" as="sourcePoint"/>
|
||||
<mxPoint x="370" y="410" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-11" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeWidth=3;fontColor=default;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="1" edge="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="430" y="490" as="sourcePoint"/>
|
||||
<mxPoint x="430" y="410" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-13" value="$$Cout$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="146" y="282" width="100" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-15" value="$$Cin$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="548" y="280" width="80" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-16" value="$$ZF$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="156" y="320" width="80" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-17" value="$$CF$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="155" y="360" width="80" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-19" value="$$\overline{Add}/Sub$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="512" y="357" width="200" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-22" value="$$\left[3:0\right]\,A$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="270" y="492" width="180" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-23" value="$$\left[3:0\right]\,B$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="492" width="180" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="U6ciwknIUaB1TWmNj2xK-24" value="$$\left[3:0\right]\,Y$$" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontColor=default;strokeWidth=1;fontStyle=1;fontSize=16;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="150" width="180" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
Loading…
Reference in New Issue