Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct coding in vhdl ALU file #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions alu.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ architecture behavioral of alu is
signal adder_carry_out : std_logic;
signal operation_type : std_logic;
signal sub : std_logic;

signal minus : std_logic; (3 downto 0);

begin
-- Make sense from control bits
Expand All @@ -42,27 +44,30 @@ begin
m_inverted(2) <= not m(2);
m_inverted(3) <= not m(3);

minus <= m when sub = '0' else
m_inverted;

-- Addition
adder_instance: carry_ripple_adder
port map(
a => n,
b => m_inverted,
ci => '1',
b => minus,
ci => sub,
s => adder_result,
co => adder_carry_out
);

-- Logical NAND operation
nand_result(0) <= not m(0) and n(0);
nand_result(1) <= not m(1) and n(1);
nand_result(2) <= not m(2) and n(2);
nand_result(3) <= not m(3) and n(3);
nand_result(0) <= not (m(0) and n(0));
nand_result(1) <= not (m(1) and n(1));
nand_result(2) <= not (m(2) and n(2));
nand_result(3) <= not (m(3) and n(3));

-- Logical NOR operation
nor_result(0) <= not m(0) or n(0);
nor_result(1) <= not m(1) or n(1);
nor_result(2) <= not m(2) or n(2);
nor_result(3) <= not m(3) or n(3);
nor_result(0) <= not (m(0) or n(0));
nor_result(1) <= not (m(1) or n(1));
nor_result(2) <= not (m(2) or n(2));
nor_result(3) <= not (m(3) or n(3));

-- Select output based on which operation was requested
d <= nand_result when opcode ="10" else
Expand Down