首页 > 解决方案 > select/when 语句 vhdl 中的多条指令

问题描述

我有一个作业,我必须使用 vhdl 来描述一个 alu,我们的老师要求我们使用select/when语句。

我几乎已经完成了,但是在某些操作码中,alu 必须“返回”两个输入的有符号和无符号乘法和除法的 msb 和 lsb

现在我的问题是我无法为一个 when编写多条指令。当我尝试编译时,我得到某种“语法错误”。

你们中的任何人都知道如何做到这一点?

这是我的实体

entity alu is
  port (
    a : in std_logic_vector(15 downto 0);
    b : in std_logic_vector(15 downto 0);
    opcode: in std_logic_vector(3 downto 0);
    res : out std_logic_vector(15 downto 0)
  );
end entity alu;

这是架构。

architecture RTL of alu is
  signal um : std_logic_vector(31 downto 0);
begin
  -- Implémenter le fonctionnement
  with opcode select res <=
    std_logic_vector(unsigned(a) + unsigned(b)) when "0000",
    std_logic_vector(unsigned(a) - unsigned(b)) when "0001",
    not a when "0010",
    a or b when "0011",
    a and b when "0100",
    a xor b when "0101",
    a when "0110", -- yet todo

    (um <= std_logic_vector(signed(a) * signed(b)); res <= um(31 downto 16)) when "0111",   -- at this line
    
    std_logic_vector(signed(a) * signed(b))(15 downto 0) when "1000",                       -- at this line
    std_logic_vector(unsigned(a) * unsigned(b))(31 downto 16) when "1001",                  -- at this line
    std_logic_vector(unsigned(a) * unsigned(b))(15 downto 0) when "1010",                   -- at this line
    a when "1011",
    b when "1100",
    x"DEAD" when others;

非常感谢您的时间。

标签: vhdl

解决方案


推荐阅读