完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
设计1个4位加减法器,实体名称为subadd4。
输入端口:A,B——实现加法与减法运算的操作数输入(4位); sub——控制端,值为’0’时实现加法运算,值为’1’时实现减法运算。 输出端口:S——和与差输出(4位); Co——进位与借位输出。 程序是: LIBRARY ieee;USE ieee.std_logic_1164.all; ENtiTY adder4 IS PORT (a0,a1,a2,a3,b0,b1,b2,b3,sub : IN std_logic; sum0,sum1,sum2,sum3,carr : OUT std_logic); END adder4; ARCHITECTURE maxpld OF adder4 IS COMPONENT adder IS PORT (a,b,c : IN std_logic; sum,carr : OUT std_logic); END COMPONENT; signal c0,c1,c2,c3:std_logic; begin process(a0,a1,a2,a3,b0,b1,b2,b3,sub)is BEGIN if(sub='0')then c0<='0'; adder0:adder PORT MAP(a0,b0,c0,sum0,c1); adder1:adder PORT MAP(a1,b1,c1,sum1,c2); adder2:adder PORT MAP(a2,b2,c2,sum2,c3); adder3:adder PORT MAP(a3,b3,c3,sum3,carr); else b0<=not b0+'1'; b1<=not b1+'1'; b2<=not b2+'1'; b3<=not b3+'1'; c0<='1'; adder4:adder PORT MAP(a0,b0,c0,sum0,c1); adder5:adder PORT MAP(a1,b1,c1,sum1,c2); adder6:adder PORT MAP(a2,b2,c2,sum2,c3); adder7:adder PORT MAP(a3,b3,c3,sum3,carr); end if; end if; end process; END maxpld; LIBRARY ieee;USE ieee.std_logic_1164.all; ENTITY adder IS PORT (a,b,c : IN std_logic; sum,carr : OUT std_logic); END adder; ARCHITECTURE maxpld OF adder ISsignal u0_s,u0_co,u1_co:std_logic; BEGIN process(a,b,c) is begin u0_s<=a xor b; u0_co<=a and b; u1_co<=u0_s and c; sum<=u0_s xor c; carr<=u0_co or u1_co; end process; END maxpld; |
|
相关推荐
1个回答
|
|
参考下这个
VHDL实验五 4位加减法器 1、四位全加减法器 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY psubadd4 IS PORT(A,B:IN STD_LOGIC_VECTOR(3 DOWNTO 0); sub:IN STD_LOGIC; S: OUT STD_LOGIC_VECTOR(3 DOWNTO 0); Co:OUT STD_LOGIC); END psubadd4; ARCHITECTURE rtl OF psubadd4 IS SIGNAL d,t:STD_LOGIC_VECTOR(3 downto 0); SIGNAL c:STD_LOGIC_VECTOR(4 downto 0); BEGIN as_add: FOR i IN 0 TO 3 GENERATE d(i)<=a(i) AND b(i); t(i)<=a(i) OR b(i); s(i)<=a(i) XOR b(i) XOR c(i); END GENERATE; c(0)<=sub; c(1)<=d(0) OR (t(0) AND c(0)); c(2)<=d(1) OR (t(1) AND d(0)) OR (t(1) AND t(0) AND c(0)); c(3)<=d(2) OR (t(2) AND d(1)) OR (t(1) AND t(2) AND d(0)) OR (t(1) AND t(2) AND t(0) AND c(0)) ; c(4)<=d(3) OR (t(3) AND d(2)) OR (t(3) AND t(2) AND d(1)) OR (t(1) AND t(2) AND t(3) AND d(0)) OR (t(3) AND t(2) AND t(1) AND t(0) AND c(0)); Co<=c(4); END rtl; 2、一位半加器 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY half_adder IS PORT(A,B:IN STD_LOGIC; S,Co:OUT STD_LOGIC); END half_adder; ARCHITECTURE rtl OF half_adder IS SIGNAL C,D:STD_LOGIC; BEGIN C<=A OR B; D<=A NAND B; Co<=NOT D; S<=C AND D; END rtl; 3、一位全加器 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY full_adder IS PORT(A,B,CIN:IN STD_LOGIC; S,CO:OUT STD_LOGIC); END full_adder; ARCHITECTURE rtl OF full_adder IS COMPONENT half_adder IS PORT(A,B:IN STD_LOGIC; S,CO:OUT STD_LOGIC); END COMPONENT; SIGNAL PCX0S,PCX0CO,PCX1CO:STD_LOGIC; BEGIN UO:half_adder PORT MAP(A,B,PCX0S,PCX0CO); U1:half_adder PORT MAP(PCX0S,CIN,S,PCX1CO); CO<=PCX0CO OR PCX1CO; END rtl; 4、LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY half_adder IS PORT(a,b: IN STD_LOGIC; s,co: OUT STD_LOGIC); END ENTITY half_adder; ARCHITECTURE half1 OF half_adder IS SIGNAL c,d:STD_LOGIC; BEGIN c<=a OR b; d<=a NAND b; co<=NOT d; s<=c AND d; END ARCHITECTURE half1; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY subadd IS PORT(A,B,C: IN STD_LOGIC; SUM,CARR: OUT STD_LOGIC); END ENTITY subadd; ARCHITECTURE ABC OF subadd IS COMPONENT half_adder IS PORT(a,b:IN STD_LOGIC; s,co:OUT STD_LOGIC); END COMPONENT ; SIGNAL u0_co,u0_s,u1_co:STD_LOGIC; BEGIN u0:half_adder PORT MAP (A,B,u0_s,u0_co); u1:half_adder PORT MAP (u0_s,C,SUM,u1_co); CARR<=u0_co OR u1_co; END ARCHITECTURE ABC; LIBRARY IEEE; USE_IEEE.STD_LOGIC_1164.ALL; ENTITY subadd_4 IS PORT(a0,b0,a1,b1,a2,b2,a3,b3: IN STD_LOGIC; c: IN STD_LOGIC; sum0,sum1,sum2,sum3: OUT STD_LOGIC_; carr: OUT STD_LOGIC); END ENTITY subadd_4; ARCHITECTURE ABC OF subadd_4 IS COMPONENT subadder IS PORT(A,B,C: IN STD_LOGIC; SUM,CARR: OUT STD_LOGIC); END COMPONENT; SIGNAL C_4:STD_LOGIC_VECTOR(4 DOWNTON 0); BEGIN SIGNAL c1,c2,c3: IN STD_LOGIC; s0:subadder PORT MAP(a0,b0,cin,sum0,c1); s1:subadder PORT MAP(a1,b1,c1,sum1,c2); s2:subadder PORT MAP(a2,b2,c2,sum2,c3); s3:subadder PORT MAP(a3,b3,c3,sum3,carr); END ARCHITECTURE ABC; /////////////////////////////////////////// LIBRARY IEEE; USE_IEEE.STD_LOGIC_1164.ALL; ENTITY subadd4 IS PORT(A,B: IN STD_LOGIC_VECTOR(3 DOWNTO 0); C: IN STD_LOGIC; SUM: OUT STD_LOGIC_VECTOR(3 DOWNTO 0); CARR: OUT STD_LOGIC); END ENTITY subadd4; ARCHITECTURE ABC OF subadd4 IS COMPONENT subadder IS PORT(A,B,C: IN STD_LOGIC; SUM,CARR: OUT STD_LOGIC); END COMPONENT; SIGNAL C_4:STD_LOGIC_VECTOR(4 DOWNTON 0); BEGIN C_4(0)<=C; s0:subadder PORT MAP(A(0),B(0),C_4(0),SUM(0),C_4(1)); s1:subadder PORT MAP(A(1),B(1),C_4(1),SUM(1),C_4(2)); s2:subadder PORT MAP(A(2),B(2),C_4(2),SUM(2),C_4(3)); s3:subadder PORT MAP(A(3),B(3),C_4(3),SUM(3),C_4(4)); CARR<=C_4(4); END ARCHITECTURE ABC; |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基本FPGA或者树莓派或者其它微处理器(尽量压缩成本且完成项目)DFB激光器稳频
1375 浏览 1 评论
2476 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1196 浏览 0 评论
3623 浏览 1 评论
3238 浏览 0 评论
2316 浏览 58 评论
6162 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-31 07:37 , Processed in 0.313597 second(s), Total 38, Slave 33 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号