我一直在研究一个接受 2 个输入、一个 3 位输入和一个 4 位输入的 vhdl 程序。3 位输入表示“2 的 n 次方”,即输入 010(即 2)将等于 2^2=4。输入 110(即 6)将产生 2^6,即 64。这将乘以从 0000 到 1111 的 4 位输入,并将答案存储为 8 位。但是,当我尝试在 VHDL 中解决此问题时,我不断收到错误“midterm_q_one.vhd(34) 处的表达式错误:表达式有 12 个元素,但必须有 8 个元素”。我是 VHDL 新手,在线搜索几乎没有结果。我想要一种方法让我的输出(在这种情况下为十六进制)将我的 2 个输入的乘积存储为 8 位值,但不知道如何。任何帮助将不胜感激,以下是我的代码。谢谢!
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity midterm_q_one is
port(en: in std_logic;
reset: in std_logic;
three_bit: in std_logic_vector(2 downto 0);
four_bit: in std_logic_vector(3 downto 0);
hex: out std_logic_vector(7 downto 0)
);
end midterm_q_one;
architecture arch of midterm_q_one is
signal temp : std_logic_vector(7 downto 0);
begin
process(en, reset, three_bit, four_bit)
begin
if(reset = '1') then
temp <= "00000000";--reset to decimal 0
elsif(en = '1') then
case three_bit is
when "000" => temp <= "00000001";--1
when "001" => temp <= "00000010";--2
when "010" => temp <= "00000100";--4
when "011" => temp <= "00001000";--8
when "100" => temp <= "00010000";--16
when "101" => temp <= "00100000";--32
when "110" => temp <= "01000000";--64
when "111" => temp <= "10000000";--128
end case;
end if;
hex <= temp * four_bit;
end process;
end arch;