ALU181设计
一、ALU181简要介绍
- 算术逻辑单元(ALU)是计算机的核心部件之一,它能执行加法和减法等算术运算,也能执行“与”、“或”、“非”等逻辑运算。算术逻辑单元的基本功能可以根据74LS181的功能用VHDL编辑而成。
- ALU181的运算功能
功能简要分析:说明: ALU执行的运算有6个输入端S3-S0、 M、Cn,能执行48种运算;M输入有特别的作用,当M=1时,屏蔽Cn,即Cn的值不影响执行的运算;当M=0时,ALU执行的运算除受S3-S0外,还受Cn值得影响。
二、设计原理和电路图
- 设计原理图
- 电路元件图
三、系统调试情况
分三种情况
- 当M=1时,波形图如下
- 当M=0,cn=0时,波形图如下
- 当M=0, Cn=1时,波形图如下
四、程序代码
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ALU181 IS
PORT ( S : IN STD_LOGIC_VECTOR(3 DOWNTO 0 );A,B : IN STD_LOGIC_VECTOR(7 DOWNTO 0); F : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);COUT : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);M,CN : IN STD_LOGIC;CO,FZ : OUT STD_LOGIC );
END ALU181;
ARCHITECTURE behav OF ALU181 IS
SIGNAL A9,B9,F9 : STD_LOGIC_VECTOR(8 DOWNTO 0);
BEGIN
A9 <= '0' & A ; B9 <= '0' & B ;
PROCESS(M,CN,A9,B9)
BEGIN
CASE S IS
WHEN "0000"=>IF M='0' THEN F9<=A9 + CN ; ELSE F9<=NOT A9; END IF;
WHEN "0001"=>IF M='0' THEN F9<=(A9 OR B9)+CN; ELSE F9<=NOT(A9 OR B9); END IF;
WHEN "0010"=>IF M='0' THEN F9<=(A9 OR (NOT B9))+CN;
ELSE F9<=(NOT A9) AND B9; END IF;
WHEN "0011"=>IF M='0' THEN F9<= "000000000"-CN ; ELSE F9<="000000000"; END IF;
WHEN "0100"=>IF M='0' THEN F9<=A9+(A9 AND NOT B9)+CN ;ELSE F9<=NOT (A9 AND B9); END IF;
WHEN "0101"=>IF M='0' THEN F9<=(A9 OR B9)+(A9 AND NOT B9)+CN ;ELSE F9<=NOT B9; END IF;
WHEN "0110"=>IF M='0' THEN F9<=A9 -B9 - CN ; ELSE F9<=A9 XOR B9; END IF;
WHEN "0111"=>IF M='0' THEN F9<=(A9 AND (NOT B9))-CN ;ELSE F9<=A9 AND (NOT B9); END IF;
WHEN "1000" =>IF M='0' THEN F9<=A9 + (A9 AND B9)+CN;ELSE F9<=(NOT A9) OR B9;END IF;
WHEN "1001" =>IF M='0' THEN F9<=A9 + B9 + CN; ELSE F9<=NOT(A9 XOR B9);
END IF;
WHEN "1010" =>IF M='0' THEN F9<=(A9 OR (NOT B9))+(A9 AND B9)+CN ;ELSE F9<=B9; END IF;
WHEN "1011" =>IF M='0' THEN F9<=(A9 AND B9)- CN ; ELSE F9<=A9 AND B9; END IF;
WHEN "1100" =>IF M='0' THEN F9<=A9 + A9 + CN; ELSE F9<= "000000001"; END IF;
WHEN "1101" =>IF M='0' THEN F9<=(A9 OR B9)+A9 + CN ;
ELSE F9<=A9 OR (NOT B9); END IF;
WHEN "1110" =>IF M='0' THEN F9<=(A9 OR(NOT B9))+A9+CN; ELSE F9<=A9 OR B9;END IF;
WHEN "1111" =>IF M='0' THEN F9<=A9-CN; ELSE F9<=A9 ; END IF;
WHEN OTHERS =>F9<= "000000000" ;
END CASE;
IF (A9= B9) THEN FZ <= '0';END IF;
END PROCESS;
F<= F9(7 DOWNTO 0) ; CO <= F9(8) ;
COUT <= "0000" WHEN F9(8) = '0' ELSE "0001" ;
END behav;