Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug fixes #1

Open
wants to merge 1 commit 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
27 changes: 16 additions & 11 deletions alu.vhd
Original file line number Diff line number Diff line change
@@ -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 b_ph : std_logic_vector (3 downto 0);
signal ci_ph : std_logic;

begin
-- Make sense from control bits
@@ -43,26 +45,29 @@ begin
m_inverted(3) <= not m(3);

-- Addition
b_ph <= m_inverted when sub = '1' else m;
ci_ph <= '1' when sub = '1' else '0';

adder_instance: carry_ripple_adder
port map(
a => n,
b => m_inverted,
ci => '1',
b => b_ph,
ci => ci_ph,
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
@@ -71,6 +76,6 @@ begin

-- Carry out bit
cout <= (adder_carry_out xor sub) when operation_type = '0' else
'0';
'0';
end;