2

我正在尝试合成一些我发现的代码,这些代码基本上将 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”。我在这里做错了什么?

亲切的问候

4

1 回答 1

3

架构的定义如下:

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

在你说end architecture之前,你需要说begin,并做架构声明部分(可以是空的)

于 2012-09-14T01:14:55.213 回答