diff options
author | crupest <crupest@outlook.com> | 2021-12-03 19:34:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-12-03 19:34:17 +0800 |
commit | 78ce0ddf1ab18e67d62b0f6b05ab010b0e4bb8c0 (patch) | |
tree | be61c6ba66ef7b9ac46e8ce5ecd69731f2c3143b /computer-organization-experiment/alu.vhdl | |
parent | 65b45752178e5c047d314d6e6852db5659c66cc9 (diff) | |
download | life-78ce0ddf1ab18e67d62b0f6b05ab010b0e4bb8c0.tar.gz life-78ce0ddf1ab18e67d62b0f6b05ab010b0e4bb8c0.tar.bz2 life-78ce0ddf1ab18e67d62b0f6b05ab010b0e4bb8c0.zip |
...
Diffstat (limited to 'computer-organization-experiment/alu.vhdl')
-rw-r--r-- | computer-organization-experiment/alu.vhdl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/computer-organization-experiment/alu.vhdl b/computer-organization-experiment/alu.vhdl new file mode 100644 index 0000000..0bb743c --- /dev/null +++ b/computer-organization-experiment/alu.vhdl @@ -0,0 +1,22 @@ +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.STD_LOGIC_UNSIGNED.ALL; +use ieee.numeric_std.all; + +entity alu is + port (A, B: in std_logic_vector(31 downto 0); ALUC: in std_logic_vector(3 downto 0); S: out std_logic_vector(31 downto 0); Z: out std_logic); +end entity; + +architecture Behavioral of alu is +begin + S <= A + B when ALUC(2 downto 0) = B"000" + else A and B when ALUC(2 downto 0) ?= B"001" + else A - B when ALUC(2 downto 0) ?= B"100" + else A or B when ALUC(2 downto 0) ?= B"101" + else A xor B when ALUC(2 downto 0) ?= B"010" + else std_logic_vector(signed(A) sll 16) and B"11111111111111110000000000000000" when ALUC(2 downto 0) ?= B"110" + else std_logic_vector(signed(A) sll to_integer(unsigned(B))) when ALUC ?= B"0011" + else std_logic_vector(signed(A) srl to_integer(unsigned(B))) when ALUC ?= B"0111" + else std_logic_vector(signed(A) sra to_integer(unsigned(B))) when ALUC ?= B"1111"; + Z <= S ?= "00000000000000000000000000000000"; +end architecture; |