VHDL:使用函数的意外END

时间:2012-09-14 01:09:23

标签: function vhdl

我正在尝试合成一些我发现的代码,它实质上将8位二进制转换为BCD。代码使用函数,我有以下错误;

Line #: parse error, unexpected END

以下是我的代码的行为部分;

architecture Behavioral of bintobcd is


function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is
variable i : integer:=0;
variable bcd : std_logic_vector(11 downto 0) := (others => '0');
variable bint : std_logic_vector(7 downto 0) := bin;

begin
for i in 0 to 7 loop  -- repeating 8 times.
    bcd(11 downto 1) := bcd(10 downto 0);  --shifting the bits.
    bcd(0) := bint(7);
    bint(7 downto 1) := bint(6 downto 0);
    bint(0) :='0';


    if (i < 7 and bcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4.
        bcd(3 downto 0) := bcd(3 downto 0) + "0011";
    end if;

    if (i < 7 and bcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4.
        bcd(7 downto 4) := bcd(7 downto 4) + "0011";
    end if;

    if (i < 7 and bcd(11 downto 8) > "0100") then  --add 3 if BCD digit is greater than 4.
        bcd(11 downto 8) := bcd(11 downto 8) + "0011";
    end if;


end loop;
return bcd;
end to_bcd;
end Behavioral;

错误指向我的最后一行“end Behavioral”。我在这里做错了什么?

亲切的问候

1 个答案:

答案 0 :(得分:3)

架构的定义如下:

architecture identifier of entity_name is
    architecture_declarative_part
begin
    architecture_statement_part
end optional(architecture) optional(architecture_simple_name) ;

在您说结束架构之前,您需要说开始,并执行架构声明部分(可以为空)