课程设计 - 4位二进制全加器全减器课件 下载本文

a1 a2 a3 SELECT B4 B3 B2 B1 1 7 12 14 3 5 11 15 2 6 A4 A3 A2 A1 B4 B3 B2 B1 SUM_4 SUM_3 SUM_2 SUM_1 10 13 1 4

3 2 7 C0 74LS283 C4 9

CIN

4 总的真值表:即将全加器真值表和全减器真值表合成而得,此处省略。 二、软件程序的设计

本设计采用Verilog HDL语言的所设计的4位二进制全加器进行仿真,下面

是具体的Verilog HDL程序:

第一步:建一VHD程序,半加器的。hadd_v.vhd library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity hadd_v is

port(a,b: in std_logic; s,c: out std_logic); end hadd_v;

architecture a of hadd_v is

signal temp: std_logic_vector(1 downto 0); begin

temp<=('0'&A)+B; s<=temp(0); c<=temp(1); end a; 编译通过

第二步:建一VHD程序,全加器。fadd_v.vhd library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity fadd_v is

port(a,b,ci :in std_logic;

s,co :out std_logic); end fadd_v;

architecture a of fadd_v is

signal temp :std_logic_vector(1 downto 0); begin

temp<=('0'&a)+b+ci; s<=temp(0); co<=temp(1); end a; 编译通过。

第三步:建一VHD程序。为程序包,加入全加,半加两个实例add_v.vhd LIBRARY ieee;

USE ieee.std_logic_1164.ALL; PACKAGE add_v IS

COMPONENT hadd_v

PORT(

a, b : IN STD_LOGIC;

s,c : OUT STD_LOGIC); END COMPONENT; COMPONENT fadd_v

PORT(

a, b,ci: IN STD_LOGIC;

s,co : OUT STD_LOGIC); END COMPONENT;

END add_v;

第四步:四位加法器程序 add4_v.VHD library ieee;

use ieee.std_logic_1164.all; use Work.add_v.all; entity add4_v is

port (A,B:in std_logic_vector(3 downto 0); S:out std_logic_vector(3 downto 0); cout :out std_logic); end add4_v;

architecture x of add4_v is signal N1,N2,N3: std_logic; begin

h0: hadd_v

port map (a=>A(0),b=>B(0),s=>S(0),c=>N1); h1: fadd_v

port map (a=>A(1),b=>B(1),ci=>N1,s=>S(1),co=>N2); h2: fadd_v

port map (a=>A(2),b=>B(2),ci=>N2,s=>S(2),co=>N3); h3: fadd_v

port map (a=>A(3),b=>B(3),ci=>N3,s=>S(3),co=>cout); end x; 结束。

结语

通过我们小组成员的共同努力,完成了由74LS283构成的4位二进制全加器的电路硬件设计和Verilog HDL软件仿真,最终我们的设计成果较好地完成了设计要求,同时我们也在本次设计过程中进一步掌握了组合逻辑电路的相关知识以及进一步熟悉Verilog HDL 语言的应用。