我面临一个问题......其中 p3,p6,p9 ,p1,p4 p7 是 8 位 std_logic_vector。
我想做 (p3+2*p6+p9)-(p1+2*p4+p7) 之类的操作,没有乘数,而是通过移位操作。(通过两个=>左移 1),其结果可能是 + 或 -五。
所以我想要签名一个。如果它超过 255,则结果为 255,否则为 8 位值。第一个 h1 给出了错误的结果。
您可以在下面找到代码
-
- Company:
-- Engineer:
--
-- Create Date: 21:01:45 01/11/2013
-- Design Name:
-- Module Name: HRZ - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity HRZ is
PORT ( CLK : IN STD_LOGIC;
RST : IN STD_LOGIC;
P1,P3,P4,P6,P7,P9 : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
MAG_HRZ : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) );
end HRZ;
architecture Behavioral of HRZ is
SIGNAL H1: signed(17 DOWNTO 0) ;
SIGNAL THRESHOLD: signed(17 DOWNTO 0):="000000000011111111";
begin
P : PROCESS(CLK)
BEGIN
H1<=SIGNED(('0'&P3+'0'&P6(7 DOWNTO 0)&'0'+'0'&P9)-('0'&P1+'0'&P4(7 DOWNTO 0)&'0'+'0'&P7));
IF(H1>=THRESHOLD) THEN
MAG_HRZ<="11111111";
ELSE
IF H1(17)='0' THEN
MAG_HRZ<=H1(7)&H1(6)&H1(5)&H1(4)&H1(3)&H1(2)&H1(1)&H1(0);
ELSE
MAG_HRZ<=NOT(H1(7)&H1(6)&H1(5)&H1(4)&H1(3)&H1(2)&H1(1)&H1(0))+'1';
END IF;
END IF;
END PROCESS P;
end Behavioral;
vh