我正在制作一个带有执行 A + 2B 选项的 ALU 但我很难将 2B 相乘并在测试台上得到正确的答案。
EG:A = 0110 B = 0011 等式为 A + 2B 我收到 0110
我的代码片段是
entity ALU is
port( A :IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
B :IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
S0 :IN STD_LOGIC ;
S1 :IN STD_LOGIC ;
M :IN STD_LOGIC ;
C0 :IN STD_LOGIC ;
Cout :OUT STD_LOGIC ;
Z :OUT STD_LOGIC ;
F :OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
SIGNAL VariableAlu : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL FTEMP : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL FTEMP2 : STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL ZTEMP : STD_LOGIC;
SIGNAL BTEMP1 : STD_LOGIC_VECTOR(4 DOWNTO 0);
END ALU ;
PROCESS(A,B,S0,S1,M,C0)
BEGIN
VariableAlu <= (S0 & S1 & C0 & M);
--M = 1 ARITHMETIC
(part that shifts it, lab teacher told us to do this)
BTEMP1(4 DOWNTO 1)<= B;
BTEMP1(0)<= '0';
when "1111" => FTEMP2 <= ((A) + BTEMP1);
任何帮助将不胜感激。
最佳答案
除了GSM所说的,你也可以只写你想要的。 IE。乘以 2。合成软件足够智能,可以识别您在做什么。 您必须记住的是,结果会太大,因此必须调整其大小。
library IEEE;
use IEEE.std_logic_1164.all;
entity input_output_adder is
port (
input_a : in std_logic_vector(4 downto 0);
input_b : in std_logic_vector(4 downto 0);
output : out std_logic_vector(4 downto 0)
);
end entity;
architecture rtl of input_output_adder is
use IEEE.numeric_std.all;
begin
output <= std_logic_vector(unsigned(input_a) + resize((unsigned(input_b) * 2), 5));
end architecture;
这将仅产生 LUT...nu 乘数。
关于vhdl - VHDL 4位向量中的无符号乘法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43142341/