【问题标题】:Is there combinational circuit design for a 6 operation ALU?6运算ALU是否有组合电路设计?
【发布时间】:2014-02-03 19:22:29
【问题描述】:

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

【问题讨论】:

  • Stack Overflow 专注于软件问题 - 这是硬件设计。尝试在Electrical Engineering 上提问
  • @MikeW - 这对于 SO 来说仍然可以,因为它是关于用 VHDL 编写实现。
  • @admdrew 有可能,但是 OP 更有可能在Electrical Engineering找到有相关硬件设计经验的人
  • @MikeW 同意,而且这个问题一开始就写得不好。
  • @MikeW - 有相当数量的 VHDLers 在 SO 和 EE 上闲逛 :)

标签: vhdl alu


【解决方案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 中进行了清理。但是,为了向后兼容 以上建议是基于函数而不是运算符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    • 2018-05-13
    • 2011-03-29
    相关资源
    最近更新 更多