【发布时间】:2021-02-18 18:32:18
【问题描述】:
我需要使用 if then 语句在 VHDL 中创建一个左移位器。我不知道我已经写了什么。我附上了照片和下面的代码。非常感谢!
LIBRARY ieee;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
entity shifter is
PORT (
input: IN UNSIGNED (7 DOWNTO 0);
shift_cntrl : IN UNSIGNED (1 DOWNTO 0);
shift_out : OUT UNSIGNED (15 DOWNTO 0)
);
end shifter;
architecture arch of shifter is
begin
process (input, shift_cntrl)
begin
if (shift_cntrl="00") then shift_out<=input;
else if (shift_cntrl="11") then shift_out<=input;
else if (shift_cntrl="01") then shift_out<=input+4;
else if (shift_cntrl="10") then shift_out<=input+8;
end if;
end process;
end arch;
【问题讨论】:
-
二次乘法的优势在于将十进制整数文字设置为另一个操作数的长度,并产生两倍于其长度的结果。综合起来,这将转化为转变。例如,
shift_out <= input * 4;将左移 2,而右侧表达式将为分配目标的每个元素提供匹配元素。提供由 shift_control 指定的移位距离的明确指示(添加似乎无效)。将else ifs 更正为elsifs。