1

I have to design a 1 bit ALU for an assignment which would then be reused to make 4 units and a 4 bit ALU.

1 bit ALU has 2 select lines and inputs A, B and a carry in.

My problem is that the select lines AND the carry in flag choose what operation to select. I just have no clue how to use the select lines and carry flag at the same time to select the operation.

For example, select lines "00" and Cin "0" is an add operation whereas Cin "1" is a subtract.

Could I do what I have done below? Thanks for your help.

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;
4

1 回答 1

0

看起来你缺少的是你可以有嵌套的 case 语句。你的代码:

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

在正确的行上,但是 case 语句必须在进程中,正如布赖恩所说,您试图将“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 => ...

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

于 2015-01-26T11:38:22.540 回答