BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / circuit / #19200同步于 2011/12/1
Circuit机器人发帖

根据之前5221调整算法写的,但是结果不对,看结果应该是cin,f1,

danielinwind
2011/12/1镜像同步0 回复
LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; ENTITY wzz IS PORT(a : IN std_logic_vector(3 DOWNTO 0); b : IN std_logic_vector(3 DOWNTO 0); na : BUFFER std_logic_vector(3 DOWNTO 0); nb : BUFFER std_logic_vector(3 DOWNTO 0); sum : buffer std_logic_vector(3 downto 0); sumttt : OUT std_logic_vector(3 downto 0); sumone: OUT std_logic_vector(3 downto 0); co : out std_logic ); END wzz; ARCHITECTURE BEHAVOR OF wzz IS FUNCTION a8421_to_5221 (input: std_logic_vector(3 downto 0)) RETURN std_logic_vector is VARIABLE result:std_logic_vector(3 downto 0); begin case input is when "0100" => result:="0110"; when "0101" => result:="1000"; when "0110" => result:="1001"; when "0111" => result:="1100"; when "1000" => result:="1101"; when "1001" => result:="1110"; when OTHERS => result:=input; end case; return(result); end a8421_to_5221; FUNCTION a5221_to_8421 (input: std_logic_vector(3 downto 0)) RETURN std_logic_vector is VARIABLE result:std_logic_vector(3 downto 0); begin case input is when "0110" => result:="0100"; when "1000" => result:="0101"; when "1001" => result:="0110"; when "1010"|"1100" => result:="0111"; when "1011"|"1101" => result:="1000"; when "1110" => result:="1001"; when OTHERS => result:=input; end case; return(result); end a5221_to_8421; FUNCTION nf_add (input1: std_logic_vector(3 DOWNTO 0); input2: std_logic_vector(3 DOWNTO 0)) RETURN std_logic_vector IS VARIABLE nresult: std_logic_vector(4 downto 0); VARIABLE m: integer RANGE 0 TO 3; CONSTANT nS_vector: std_logic_vector(0 to 3) :="0101"; CONSTANT nCo_vector: std_logic_vector(0 to 3) :="0011"; VARIABLE ncin: std_logic:='0'; VARIABLE i:integer; BEGIN FOR i in 0 TO 3 LOOP m:=0; IF(input1(i)='1') THEN m:=m+1; END IF; IF(input2(i)='1') THEN m:=m+1; END IF; IF(nCin='1') THEN m:=m+1; END IF; nresult(i) := nS_vector(m); nCin := nCo_vector(m); END LOOP; RETURN(nresult); END nf_add; BEGIN nb <= a8421_to_5221(b); na <= a8421_to_5221(a); PROCESS(na,nb) VARIABLE cin,f1,f2: std_logic; VARIABLE flag: std_logic_vector(3 downto 0):="0000"; VARIABLE n: integer RANGE 0 TO 3; CONSTANT S_vector: std_logic_vector(0 to 3):= "0101"; CONSTANT Co_vector: std_logic_vector(0 to 3):= "0011"; variable result1 : std_logic_vector(3 downto 0); VARIABLE i:integer; BEGIN f1:='0'; f2:='0'; cin:='0'; FOR i in 0 TO 3 LOOP n:=0; IF(na(i)='1') THEN n:=n+1; END IF; IF(nb(i)='1') THEN n:=n+1; END IF; IF(cin='1') THEN n:=n+1; END IF; result1(i):=S_vector(n); cin :=Co_vector(n); IF(i=1) THEN f1:=cin; END IF; IF(i=2) THEN f2:=cin; END IF; END LOOP; co<=cin; sumone<=result1; IF(f1='1') THEN result1:=nf_add(result1,"0010"); END IF; IF(f2='1') THEN result1:=nf_add(result1,"1111"); END IF; sum <= result1; sumttt <= a5221_to_8421(sum); end process; END BEHAVOR;
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。