umairsiddiqui
Full Member level 2
![Full Member level 2](/styles/images/ranks/elevel2.gif)
consider this code...
which is arithmetic unit of ALU:
supports: ADD, SUB, ADC and SBB
problem is that given code require 17bit subtractor, 16-bit adder, and 16-bit adder with carry-in. please help how to reduce it size... :?
which is arithmetic unit of ALU:
supports: ADD, SUB, ADC and SBB
problem is that given code require 17bit subtractor, 16-bit adder, and 16-bit adder with carry-in. please help how to reduce it size... :?
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity alu is
Port ( a : in std_logic_vector(15 downto 0);
b : in std_logic_vector(15 downto 0);
cin : in std_logic;
op : in std_logic_vector(1 downto 0);
c : out std_logic_vector(15 downto 0);
cout : out std_logic;
ofl : out std_logic);
end alu;
architecture Behavioral of alu is
begin
process(a, b, cin, op)
variable c_select : std_logic;
variable a_temp,
b_temp,
c_temp : std_logic_vector(16 downto 0);
begin
a_temp := "0" & a;
b_temp := "0" & b;
case op(1) is
when '0' => c_select := '0';
when '1' => c_select := cin;
when others => c_select := '0';
end case;
case op(0) is
when '0' => c_temp := a_temp + b_temp + c_select;
when '1' => c_temp := a_temp - (b_temp + c_select);
when others => c_temp := (others => '0');
end case;
c <= c_temp(15 downto 0);
cout <= c_temp(16);
ofl <= c_temp(15) xor c_temp(14);
end process;
end Behavioral;