VHDL程序:四位乘法器

VHDL程序:四位乘法器

--1.  IF语句行为级描述

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

entity multip_4 is
    port (a,b:in std_logic_vector(3 downto 0);
            y:out std_logic_vector(7 downto 0));
end multip_4;

architecture behave of multip_4 is
signal s0,s1,s2,s3:std_logic_vector(3 downto 0);
begin
    process(a,b,s0,s1,s2,s3)
    begin
     if b(0)='0' then s0<="0000";
     else s0<=a;
     end if;
     if b(1)='0' then s1<="0000";
     else s1<=a;
     end if;
     if b(2)='0' then s2<="0000";
     else s2<=a;
     end if;
     if b(3)='0' then s3<="0000";
     else s3<=a;
     end if;
     y<=("0000"&s0)+("000"&s1&'0')+("00"&s2&"00")+('0'&s3&"000");
    end process;
end behave;

--1.  IF语句行为级描述

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

entity multip_4 is
    port (a,b:in std_logic_vector(3 downto 0);
            y:out std_logic_vector(7 downto 0));
end multip_4;

architecture behave of multip_4 is
signal s0,s1,s2,s3:std_logic_vector(3 downto 0);
begin
    process(a,b,s0,s1,s2,s3)
    begin
     if b(0)='0' then s0<="0000";
     else s0<=a;
     end if;
     if b(1)='0' then s1<="0000";
     else s1<=a;
     end if;
     if b(2)='0' then s2<="0000";
     else s2<=a;
     end if;
     if b(3)='0' then s3<="0000";
     else s3<=a;
     end if;
     y<=("0000"&s0)+("000"&s1&'0')+("00"&s2&"00")+('0'&s3&"000");
    end process;
end behave;

--2.  条件信号代入语句行为级描述

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

entity multip_4 is
    port (a,b:in std_logic_vector(3 downto 0);
            y:out std_logic_vector(7 downto 0));
end multip_4;

architecture behave of multip_4 is
signal s1:std_logic_vector(3 downto 0);
signal s2:std_logic_vector(4 downto 0);
signal s3:std_logic_vector(5 downto 0);
signal s4:std_logic_vector(6 downto 0);
begin
    s1<=a when b(0)='1' else "0000";
    s2<=(a&'0')when b(1)='1'else"00000";
    s3<=(a&"00")when b(2)='1'else"000000";
    s4<=(a&"000")when b(3)='1'else"0000000";
    y<=s1+s2+s3+('0'&s4);
end behave;

--2.  条件信号代入语句行为级描述

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

entity multip_4 is
    port (a,b:in std_logic_vector(3 downto 0);
            y:out std_logic_vector(7 downto 0));
end multip_4;

architecture behave of multip_4 is
signal s1:std_logic_vector(3 downto 0);
signal s2:std_logic_vector(4 downto 0);
signal s3:std_logic_vector(5 downto 0);
signal s4:std_logic_vector(6 downto 0);
begin
    s1<=a when b(0)='1' else "0000";
    s2<=(a&'0')when b(1)='1'else"00000";
    s3<=(a&"00")when b(2)='1'else"000000";
    s4<=(a&"000")when b(3)='1'else"0000000";
    y<=s1+s2+s3+('0'&s4);
end behave;

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值