【问题标题】:1 bit ALU whose operations depend on carry in1 位 ALU,其操作取决于进位
【发布时间】:2015-01-25 19:34:44
【问题描述】:

我必须为分配设计一个 1 位 ALU,然后将其重新用于制造 4 个单元和一个 4 位 ALU。

1 位 ALU 有 2 条选择线和输入 A、B 和一个进位。

我的问题是选择行和进位标志选择要选择的操作。我只是不知道如何同时使用选择行和携带标志来选择操作。

例如,选择行“00”,Cin“0”是加法运算,而Cin“1”是减法运算。

我可以做我在下面所做的吗?感谢您的帮助。

entity ALU1Bit is
port(
    A:  IN std_logic_vector;
    B:  IN std_logic; 
    carryIn:      IN std_logic;                                  
    operation: IN std_logic_vector(1 downto 0); 

    F:   OUT std_logic;
    carryOut: OUT std_logic
    );
end ALU1Bit;

architecture Behavioral of ALU1Bit is

component Adder1Bit
port(
    carryIn:  IN std_logic;
    A: IN std_logic;
    B: IN std_logic;

    output:  OUT std_logic;
    F: OUT std_logic
    );
end component;

begin
carryIn <= '0';
    case operation is
        when...
carryIn <= '1';
    case operation is
        when...

end Behavioral;

【问题讨论】:

  • 没有。一方面,分配给输入端口是一个错误。

标签: vhdl alu


【解决方案1】:

您似乎缺少的是可以嵌套 case 语句。你的代码:

carryIn <= '0';
    case operation is
        when...
carryIn <= '1';
    case operation is
        when...

在正确的行上,但 case 语句必须在进程中,正如 Brian 所说,您试图将“0”和“1”分配给进位输入,这是不允许的。我认为你对这两行的意思是让它们像另一个案例陈述一样工作。你想要更多类似的东西:

process (carryIn, operation, ...)
begin
    case carryIn is
        when '0' =>
            case operation is
                when "00" => ...
                when "01" => ..
            end case;
        when '1' =>
            case operation is =>
            ...
    end case;
end process;

您似乎可能有重叠的案例,即此结构中的两个或多个案例实际上做同样的事情。这很糟糕,因为每次您需要更改这些情况下发生的情况时,都必须更改两次,这很容易出错。

在这种情况下,您可以有一个与上述类似的 case 语句,它使用枚举类型简单地分配操作模式,例如:

type ALU_OP_type is (ADD, SUBTRACT, ...);
signal aluOp : ALU_OP_type;

然后在你的过程中:

    case carryIn is
        when '0' =>
            case operation is
                when "00" => aluOp <= ADD;
                when "01" => aluOp <= SUBTRACT;

等等。最后是另一个使用这些简单可读操作做某事的 case 语句(可能在一个单独的进程中):

    case aluOp is
        when ADD => ...
        when SUBTRACT => ...

等等。然后,您的代码很好地分为“制定我们将要做什么”和“做某事”。如果您没有重复的进位/操作组合,那么这可能不值得。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多