⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alu.vhd

📁 X8086的VHDL源码
💻 VHD
📖 第 1 页 / 共 2 页
字号:
			end if;
		else
			if (alu_out = "0000000000000000") then
				O_STFR(3) <= '1';
			else
				O_STFR(3) <= '0';
			end if;
		end if;
	end process;

    STATE_FREG_4_SFR_sign_frag : 
	process(b_w,alu_out)
	begin
		if (b_w = '1') then
			O_STFR(4) <= alu_out(15);
		else
			O_STFR(4) <= alu_out(7);  
        end if;
	end process;

	STATE_FREG_5_OFR_overflow_frag : 
	process(I_ALUCS,b_w,alu_out,I_TR1PLS,I_TR2DIV,mul_out,I_CFR,I_ADJUST)
	begin
		case I_ALUCS is
		when GEN =>		
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and not(I_TR2DIV(15));
				else
					O_STFR(5) <= I_TR1PLS(15) nor not(I_TR2DIV(15));
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and not(I_TR2DIV(7));
				else
					O_STFR(5) <= I_TR1PLS(7) nor not(I_TR2DIV(7));
			    end if;
			end if;	
		when KA =>
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and I_TR2DIV(15);
				else
					O_STFR(5) <= I_TR1PLS(15) nor I_TR2DIV(15);
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and I_TR2DIV(7);
				else
					O_STFR(5) <= I_TR1PLS(7) nor I_TR2DIV(7);
				end if;
			end if;
		when JOU =>
			if(b_w = '0') then ---------------FR setting--
				case mul_out(15 downto 8) is --  
				when "00000000" =>
					O_STFR(5) <= '0'; --of	--
				when others	=> 
					O_STFR(5) <= '1'; --of	--  
				end case; --  
			else 
				case mul_out(31 downto 16) is --
				when "0000000000000000" => 
					O_STFR(5) <= '0';	--of --
				when others	=> 
					O_STFR(5) <= '1';	--of --
				end case;
			end if;	
		when NO => --NOT
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and I_TR2DIV(15);
				else
					O_STFR(5) <= I_TR1PLS(15) nor I_TR2DIV(15);
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and I_TR2DIV(7);
				else
					O_STFR(5) <= I_TR1PLS(7) nor I_TR2DIV(7);
				end if;
			end if;
		when KATU =>
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and I_TR2DIV(15);
				else
					O_STFR(5) <= I_TR1PLS(15) nor I_TR2DIV(15);
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and I_TR2DIV(7);
				else
					O_STFR(5) <= I_TR1PLS(7) nor I_TR2DIV(7);
				end if;
			end if;
		when MATA =>
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and I_TR2DIV(15);
				else
					O_STFR(5) <= I_TR1PLS(15) nor I_TR2DIV(15);
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and I_TR2DIV(7);
				else
					O_STFR(5) <= I_TR1PLS(7) nor I_TR2DIV(7);
				end if;
			end if;
		when HAI =>
			if (b_w = '1') then
				if (alu_out(15) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(15) and I_TR2DIV(15);
				else
					O_STFR(5) <= I_TR1PLS(15) nor I_TR2DIV(15);
				end if;
			else
				if (alu_out(7) = '0') then --of check
					O_STFR(5) <= I_TR1PLS(7) and I_TR2DIV(7);
				else
					O_STFR(5) <= I_TR1PLS(7) nor I_TR2DIV(7);
				end if;
			end if;
		when HSIF => 
			if (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(15) xor I_TR1PLS(14); --of
			else
				O_STFR(5) <= I_TR1PLS( 7) xor I_TR1PLS( 6); --of
            end if;
		when RMSIF =>
			if (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(14); --of
			else
				O_STFR(5) <= I_TR1PLS(6); --of
			end if;
		when SMSIF =>
			O_STFR(5) <= '0'; --of
		when HRO =>
			if (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(15) xor I_TR1PLS(14); --of
			else
				O_STFR(5) <= I_TR1PLS( 7) xor I_TR1PLS( 6); --of
			end if;
		when MRO =>
			if (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(15) xor I_TR1PLS(0); --of
			else 
				O_STFR(5) <= I_TR1PLS( 7) xor I_TR1PLS(0); --of
			end if;
		when CHRO =>
			if (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(15) xor I_TR1PLS(14); --of
			else
				O_STFR(5) <= I_TR1PLS( 7) xor I_TR1PLS( 6); --of
			end if;
		when CMRO =>
			if    (b_w = '1') then
				O_STFR(5) <= I_TR1PLS(15) xor I_CFR;	--of
			else
				O_STFR(5) <= I_TR1PLS( 7) xor I_CFR;	--of
			end if;
		when ALUNEG	=>
			if (I_ADJUST = "11") then --of check	
				if (alu_out = "1111111111111111") then
					O_STFR(5) <= '0';
				else
					O_STFR(5) <= '1';
				end if;
			else
				if (b_w = '0') then
					if (I_TR1PLS = "0000000010000000") then	
						O_STFR(5) <= '1';
					else
						O_STFR(5) <= '0';
					end if;
				else
					if (I_TR1PLS = "1000000000000000") then
						O_STFR(5) <= '1';
					else
						O_STFR(5) <= '0';
					end if;
				end if;
			end if;
		when  others   => 
			O_STFR(5) <= '0';
		end case;
	end process;

	SUBTMP : 
	process (I_ALUCS,I_ADJUST,I_DIVF,b_w,I_TR1PLS,I_TR2DIV,I_USECARRY,I_CFR,I_BORROW)
    begin
		if (I_ALUCS = GEN) then			
			if (I_ADJUST = "00" or I_ADJUST = "11") then
				if(I_DIVF = '1')then
					if(b_w = '0')then	--when div
						sub <= ("00000000"&I_BORROW&I_TR1PLS(7 downto 0))-("000000000"&I_TR2DIV(7 downto 0)); --sub
					else
						sub <= (I_BORROW&I_TR1PLS)-('0'&I_TR2DIV);
					end if;
				else --generally
					if(b_w = '0')then
						sub <= ("000000000"&I_TR1PLS(7 downto 0))-("000000000"&I_TR2DIV(7 downto 0)) 
							 - ("000000000000000"&(I_USECARRY and I_CFR)); --sub
					else
						sub <= ('0'&I_TR1PLS)-('0'&I_TR2DIV)-("000000000000000"&(I_USECARRY and I_CFR));
					end if;
				end if;
			else
				sub <= "00000000000000000";
			end if;
		else
			sub <= "00000000000000000";
		end if;			
	end process;

	MULTMP : 
	process (I_ALUCS,I_ADJUST,b_w,I_TR1PLS,I_TR2DIV)
    begin
		if    (I_ALUCS = JOU) then	
			case I_ADJUST is
			when "01" => --AAD (ASCII ADJUST for MULTIPLY)
		 		mul_out <= ("000000000000000000000000"&I_TR1PLS(12 downto 8)&"000")+("000000000000000000000000"&I_TR1PLS(14 downto 8)&'0')
						   + ("000000000000000000000000"&I_TR1PLS(7 downto 0));	--AAD
			when "10" => --for CWD (CHANGE WORD to DOUBLE WORD)
				mul_out	<= (others => I_TR1PLS(15));	
			when "11" => --byte MUL out adjust(2 complement conversion when ALU_CS=NEG)
				mul_out	<= "0000000000000000"&I_TR1PLS(7 downto 0)&I_TR2DIV(15 downto 8);	
  			when others => 
				if(b_w = '0')then --addition for mul
					mul_out <= ("000000000000000000000000"&I_TR1PLS(7 downto 0))+("000000000000000000000000"&I_TR2DIV(7 downto 0));	
				else              --addition for mul
					mul_out <= ("0000000000000000"&I_TR1PLS)+("0000000000000000"&I_TR2DIV);	
				end if;
			end case;
		elsif(I_ALUCS = ALUNEG) then
			if (I_ADJUST = "11") then
				if(b_w = '0') then
					mul_out	<= "0000000000000000"&(not I_TR1PLS)+"00000000000000000000000000000001";
				else
					mul_out	<= (not (I_TR1PLS&I_TR2DIV))+"00000000000000000000000000000001";
				end if;
			else
				mul_out <= "00000000000000000000000000000000";
			end if;
		else
			mul_out <= "00000000000000000000000000000000";
		end if;
	end process;

	OUTTMP_FOR_ADJUST : 
	process (I_ALUCS,I_ADJUST,I_TR1PLS,I_AFR)
    begin
		if (I_ALUCS <= GEN) then
			if (I_ADJUST = "10") then --ASCII ADJUST for subtraction
				case I_TR1PLS(3 downto 0) is
				when "1010" | "1011" | "1100" | "1101" | "1110" | "1111" =>	--when AL>9  
					out_tmp <= I_TR1PLS - "0000000000000110"; --adjust(+06H)
				when others => 
					if(I_AFR = '1')then
		 				out_tmp <= I_TR1PLS - "000000000000110";	--adjust(+06H)
					else
						out_tmp <= I_TR1PLS;
					end if;
				end case;
			else
				out_tmp <= "0000000000000000";
			end if;
		else
			out_tmp <= "0000000000000000";
		end if;
	end process;

	AFCS : 
	process (I_ALUCS,I_ADJUST,I_TR1PLS,I_AFR)
    begin
		if    (I_ALUCS = GEN) then
			if (I_ADJUST = "10") then
				case I_TR1PLS(3 downto 0) is
				when "1010" | "1011" | "1100" | "1101" | "1110" | "1111" =>	--when AL>9  
					af_cs	<=	'1';
				when others => 
					if(I_AFR = '1')then
						af_cs	<=	'1';
					else
						af_cs	<= '0';
					end if;
				end case;
			else
				af_cs <= '0';
			end if;
		elsif (I_ALUCS = KA) then
			if (I_ADJUST = "10") then
				case I_TR1PLS(3 downto 0) is
				when "1010" | "1011" | "1100" | "1101" | "1110" | "1111" => --when AL>9  
					af_cs	<=	'1';
				when others => 
					if(I_AFR = '1')then
						af_cs	<=	'1';
					else
						af_cs	<= '0';
					end if;
				end case;
			else
				af_cs <= '0';
			end if;
		else
			af_cs <= '0';
		end if;
	end process;

	CFCS : 
	process (I_ALUCS,I_ADJUST,I_CFR,out_tmp)
    begin
		if    (I_ALUCS = GEN) then
			if (I_ADJUST = "10") then 
				case out_tmp(7 downto 4) is
				when "1010" | "1011" | "1100" | "1101" | "1110" | "1111" => --when AH>9 
					cf_cs <= '1';
				when others => 
					if(I_CFR = '1')then
						cf_cs	<=	'1';
					else
						cf_cs	<=	'0';
					end if;
				end case;
			else
				cf_cs <= '0';
			end if;	
		elsif (I_ALUCS = KA)	then
			if (I_ADJUST = "10") then
				case out_tmp(7 downto 4) is
				when "1010" | "1011" | "1100" | "1101" | "1110" | "1111" => --when AH>9 
					cf_cs <= '1';
				when others => 
					if(I_CFR = '1')then
						cf_cs	<=	'1';
					else
						cf_cs	<=	'0';
					end if;
				end case;
			else
				cf_cs <= '0';
			end if;
		else 
			cf_cs <= '0';
		end if;
	end process;

	process(I_BORROW,sub)
	begin
		if (I_BORROW = '1') then --quotient check
			O_QUOF <= '1';
		else																														  
			O_QUOF <= not sub(16);
		end if;	
	end process;

end RTL;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -