首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >6操作ALU有组合电路设计吗?

6操作ALU有组合电路设计吗?
EN

Stack Overflow用户
提问于 2014-02-03 19:22:29
回答 1查看 254关注 0票数 1

我正试图用VHDL创建一个ALU,我很难实现其中的几个操作。我已经实现了加、减和或操作,但是我想知道如何实现逻辑移位操作?ALU是32位,但任何设计都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-03 20:37:49

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

代码语言:javascript
运行
复制
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.

因此,基于此,您可以简单地编写如下代码:

代码语言:javascript
运行
复制
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中被清理过了。然而,为了向后兼容性,上述建议是基于函数而不是操作符。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21535881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档