词条 | 四位全加器 |
释义 | 四位全加器的工作原理 加法器是数字系统中的基本逻辑器件。例如:为了节省资源,减法器和硬件乘法器都可由加法器来构成。但宽位加法器的设计是很耗费资源的,因此在实际的设计和相关系统的开发中需要注意资源的利用率和进位速度等两方面的问题。多位加法器的构成有两种方式:并行进位和串行进位方式。并行进位加法器设有并行进位产生逻辑,运算速度快;串行进位方式是将全加器级联构成多位加法器。通常,并行加法器比串行级联加法器占用更多的资源,并且随着位数的增加,相同位数的并行加法器比串行加法器的资源占用差距也会越来越大。 四位全加器可对两个多位二进制数进行加法运算,同时产生进位。当两个二进制数相加时,较高位相加时必须加入较低位的进位项(Ci),以得到输出为和(S)和进位(C0)。 (一) 半加器 VHDL语言描述语句为: so<=a xor b; co<=a and b 程序设计: library ieee; use ieee.std_logic_1164.all; entity h_adder is port (a,b:in std_logic; so,co:out std_logic); ――定义输入、输出端口 end h_adder; architecture bh of h_adder is begin so<=a xor b; ――“异或”运算 co<=a and b; ――“与”运算 end bh; 四位全加器程序代码如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity add4 is port(cin:in std_logic; a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); cout:out std_logic); end add4; architecture beh of add4 is signal sint:std_logic_vector(4 downto 0); signal aa,bb:std_logic_vector(4 downto 0); begin aa<='0' & a(3 downto 0); --4位加数矢量扩为5位,提供进位空间 bb<='0' & b(3 downto 0); sint<=aa+bb+cin; s(3 downto 0)<=sint(3 downto 0); cout<=sint(4); end beh; 四位全加器 Verilog HDL语言代码如下: module adder4(cout,sum,a,b,cin); output[3:0] sum; output cout; input[3:0] a,b; input cin; assign {cout,sum}=a+b+cin; endmodule |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。