我有一个项目,我应该开发一个RISC微处理器。这涉及在行为模型中创建ALU。但是在模拟设计时似乎存在问题/错误/警告。 大多数操作都正常工作,但以下情况除外:
比较2个输入:当数字相等时,零标志未被设置。 (不相等的数字正常工作)。
警告:算术操作数中有一个'U'|'X'|'W'|'Z'|' - ',结果为'X'(es)。
(每1 ps出现一次,可能是由于过程中的等待声明)
我希望使用std_logic_vector,尽管我读到它们非常混乱。
另外,当我尝试使用比较命令(更新标志但不存储输出寄存器中的差异)时会出现问题。 如果命令在VHDL中执行?他们同时被处决了吗?或逐行??
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ALU IS
PORT(
INPUT1 , INPUT2: IN STD_LOGIC_VECTOR(7 DOWNTO 0 ) ;
CARRYIN : IN STD_LOGIC ;
ZERO,CARRYOUT : OUT STD_LOGIC ;
OUTPUT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0 ) ;
CONTROL : IN STD_LOGIC_VECTOR(7 DOWNTO 0 )
) ;
END ALU ;
ARCHITECTURE OPERATION OF ALU IS
SIGNAL TMP : STD_LOGIC_VECTOR( 8 DOWNTO 0 ) ;
BEGIN
PROCESS
BEGIN
IF( CONTROL = "00110000" OR CONTROL(7 DOWNTO 3 ) = "00001" ) THEN TMP <= CARRYIN & ( INPUT1 AND INPUT2 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "00010" ) THEN TMP <= CARRYIN & ( INPUT1 OR INPUT2 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "00011" ) THEN TMP <= CARRYIN & ( INPUT1 XOR INPUT2 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "00100" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)+1 ) , 9 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "00101" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)-1 ) , 9 ) ;
ELSIF( CONTROL = "10001100" ) THEN TMP <= '0' & (NOT INPUT1) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "11000" OR CONTROL(7 DOWNTO 2 ) = "110010" OR CONTROL = "110-11--" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)+CONV_INTEGER(INPUT2) ) , 9 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "11100" OR CONTROL(7 DOWNTO 2 ) = "111010" OR CONTROL = "111-11--" OR CONTROL(7 DOWNTO 3 ) = "00000" OR CONTROL = "00111000" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)-CONV_INTEGER(INPUT2) ) , 9 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "11010" OR CONTROL(7 DOWNTO 2 ) = "110110" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)+CONV_INTEGER(INPUT2)+CONV_INTEGER(CARRYIN) ) , 9 ) ;
ELSIF( CONTROL(7 DOWNTO 3 ) = "11110" OR CONTROL(7 DOWNTO 2 ) = "111110" ) THEN TMP <= CONV_STD_LOGIC_VECTOR( ( CONV_INTEGER(INPUT1)-CONV_INTEGER(INPUT2)-CONV_INTEGER(CARRYIN) ) , 9 ) ;
END IF ;
IF ( TMP( 7 DOWNTO 0 ) = "00000000" ) THEN ZERO <= '1' ;
ELSE ZERO <= '0' ;
END IF ;
IF( CONTROL(7 DOWNTO 3 ) = "00000" OR CONTROL = "00111000" ) THEN
TMP( 7 DOWNTO 0 ) <= INPUT1 ;
END IF ;
OUTPUT <= TMP( 7 DOWNTO 0 ) ;
CARRYOUT <= TMP(8) ;
WAIT FOR 1 PS;
END PROCESS ;
END OPERATION ;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
ENTITY test_tb IS
END test_tb;
ARCHITECTURE behavior OF test_tb IS
COMPONENT ALU
PORT(
INPUT1 , INPUT2: IN STD_LOGIC_VECTOR(7 DOWNTO 0 ) ;
CARRYIN : IN STD_LOGIC ;
ZERO,CARRYOUT : OUT STD_LOGIC ;
OUTPUT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0 ) ;
CONTROL : IN STD_LOGIC_VECTOR(7 DOWNTO 0 )
) ;
END COMPONENT ;
signal i1,i2,ctrl,opt : std_logic_vector(7 downto 0 ) := "00000000" ;
signal cin,cout,zero : std_logic := '0';
BEGIN
uut: alu PORT MAP ( i1,i2,cin,zero,cout,opt,ctrl ) ;
stim_proc: process
begin
i1 <= "10000000" ;
i2 <= "10000000" ;
ctrl <= "11011010" ;
cin <= '0' ;
wait for 5 ps;
ctrl <= "00111000" ;
wait for 5 ps ;
wait;
end process;
END;
答案 0 :(得分:0)
问题在于 CONTROL =“111-11 - ”形式的陈述以及'U'|'X'|'W'|'Z'|''的表达方式'在您使用的库函数中处理。
- &GT;长答案的短信:避免使用'U'|'X'|'W'|'Z'|' - '。使用'0'和'1'位的显式比较而不是
答案 1 :(得分:0)
不幸的是,这段代码并不符合您的期望:
CONTROL = "111-11--"
它实际上比较了CONTROL,看它是否将第4,第6和第7位设置为-
,而不是将它们用作“不关心”匹配!令人难以置信的,但这就是它被指定工作多年的方式:(
你想要的是
std_match(CONTROL, "111-11--")
将按照您的预期进行无关紧要的比较。