首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ALU + Shift Reg

ALU + Shift Reg
EN

Stack Overflow用户
提问于 2013-10-31 10:54:37
回答 1查看 2.1K关注 0票数 0

我得做一个8位的ALU,它连接到一个移位寄存器。我认为这是ALU的代码,但是用重置和时钟连接8位移位寄存器的最好方法是什么?我不知道如何使用内部信号来连接这两个组件,它们是否都有单独的

代码语言:javascript
复制
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;              -- Calling libary's to be used
use IEEE.NUMERIC_STD.ALL;

entity lu is
port(   Clk : in std_logic;                -- The clock signal
        A : in signed(7 downto 0);         -- The A Input
        B : in signed(7 downto 0);         -- The B Input
        OPCODE : in unsigned(2 downto 0);  -- Op code entered into ALU
        RES :in  std_logic;                -- The reset pin
        Q : out signed(7 downto 0)         -- The Output of LU
        );
end lu;                                    -- End Entity


architecture Behavioral of lu is

signal Reg1,Reg2,Reg3 : signed(7 downto 0) := (others => '0'); --The signal declaration 

begin

Reg1 <= A;        -- Linking Reg1 Signal to Input A
Reg2 <= B;        -- Linking Reg2 Signal to Input B
Q <= Reg3;        -- Linking Output Q to Signal Reg3

process(Clk)

begin

    if(rising_edge(Clk)) then -- Calculate at the positive edge of clk
        case OPCODE is

            when "000" => 
                Reg3 <= Reg1 + Reg2;    -- Output is = to addition

            when "001" => 
                Reg3 <= Reg1 - Reg2;    -- Output is = to subtraction

            when "010" => 
                Reg3 <= not Reg1;       -- Output is = to NOT gate

            when "011" => 
                Reg3 <= Reg1 nand Reg2; -- Output is = to NAND gate 

            when "100" => 
                Reg3 <= Reg1 nor Reg2;  -- Output is = to NOR gate  

            when "101" => 
                Reg3 <= Reg1 and Reg2;  -- Output is = to AND gate

            when "110" => 
                Reg3 <= Reg1 or Reg2;   -- Output is = to OR gate 

            when "111" => 
                Reg3 <= Reg1 xor Reg2;  -- Output is = to XOR gate  


            when others =>              -- If anyother Input Outputs nothing
                NULL;

        end case;       
    end if;

end process;    

end Behavioral;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-01 00:57:05

假设您打算向所提供的ALU代码中添加逻辑操作,则需要进行两个更改:

1)在端口列表中,增加opcode信号的宽度,以便可以添加新的操作码值:

代码语言:javascript
复制
    OPCODE: in unsigned(3 downto 0); -- Operation selection for the ALU

2)在case语句中,只需添加执行逻辑操作的新条件和代码:

代码语言:javascript
复制
    case OPCODE is
        ...

        when "1000" =>
            Reg3 <= Reg1 srl to_integer(Reg2);  -- Reg3 <= Reg1 shifted Reg2 bits to the right
        when "1001" =>
            Reg3 <= Reg1 sll to_integer(Reg2);  -- Reg3 <= Reg1 shifted Reg2 bits to the left
        when "1010" =>
            Reg3 <= Reg1 ror to_integer(Reg2);  -- Reg3 <= Reg1 rotated Reg2 bits to the right
        when "1011" =>
            Reg3 <= Reg1 rol to_integer(Reg2);  -- Reg3 <= Reg1 rotated Reg2 bits to the right
        when others =>
            Reg3 <= (others => '0');
    end case;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19704547

复制
相关文章

相似问题

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