是否有6个操作ALU的组合电路设计?

时间:2014-02-03 19:22:30

标签: vhdl alu

我正在尝试用VHDL创建一个ALU,而我很难实现几个操作。我已经实现了加,减,和或运算,但我想知道如何实现逻辑移位操作? ALU是32位,但任何设计都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

numeric_std包中包含逻辑移位操作,shift_rightshift_left

function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
-- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
-- Result: Performs a shift-left on an UNSIGNED vector COUNT times.
--         The vacated positions are filled with '0'.
--         The COUNT leftmost elements are lost.

function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
-- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
-- Result: Performs a shift-right on an UNSIGNED vector COUNT times.
--         The vacated positions are filled with '0'.
--         The COUNT rightmost elements are lost.

因此,基于此,您只需编写如下代码:

library ieee;
use ieee.numeric_std.all;

architecture syn of mdl is
  signal arg   : std_logic_vector(31 downto 0);
  signal count : std_logic_vector( 4 downto 0);
  signal res_r : std_logic_vector(31 downto 0);
  signal res_l : std_logic_vector(31 downto 0);
begin
  res_r <= std_logic_vector(shift_right(unsigned(arg), to_integer(unsigned(count))));
  res_l <= std_logic_vector(shift_left(unsigned(arg), to_integer(unsigned(count))));
end architecture;

这些操作是可综合的,如果可以的话,可以很好地映射到FPGA资源 是你的目标设备。

以前围绕VHDL移位/旋转运算符存在一些混淆, 见this link, 但它已在VHDL-2008中清理过。但是,为了向后兼容 上述建议是基于函数而不是运算符。