Morell
Member level 1
Hi everyone
I need help with writhing this combinational ALU
Here is my code
and here are my problems
1- I want to add two 8-bit inputs (input_1 and Input_2) WITH CARRY!!!
so Output should be a 9-bit signal or port.
but when I define Output as a 9-bit port, a warining comes up in synthesize
and an error comes up during simulating with ISIM (The simulator is stopped)
So what should I do to add two 8-bits and put it in a 9-bit signal or port?
2- My secend problem is with multiplying part.
I want to use the Output port right here but it should be 16-bit port.
first : i dont know the code or function that does this on std_logic_vector
secend : if I define output as a 16-bit port, I will be facing some other problems with adding part
Please help me, I am really confused
- - - Updated - - -
Hi Guys
I wrote a new code and it seems to work correctly
what do you think about this one
I need help with writhing this combinational ALU
Here is my code
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity PocketCalculator is Generic (Bits : integer := 8); Port ( Input_1 : in STD_LOGIC_VECTOR (Bits-1 downto 0):=(Others =>'0'); Input_2 : in STD_LOGIC_VECTOR (Bits-1 downto 0):=(Others =>'0'); Select_Operator : in STD_LOGIC_VECTOR (2 downto 0):=(Others =>'0'); Output : out STD_LOGIC_VECTOR (Bits-1 downto 0):=(Others =>'0')); end PocketCalculator; architecture Behavioral of PocketCalculator is begin Process(Input_1,Input_2,Select_Operator) Begin Case Select_Operator is When "100" => Output <= Input_1 + Input_2; When "010" => -- Right here I have to do the multiply part, -- and I dont know what to write here When "001" => Output <= Input_1 + not Input_2 + 1; When Others => NULL; End Case; End Process; end Behavioral;
and here are my problems
1- I want to add two 8-bit inputs (input_1 and Input_2) WITH CARRY!!!
so Output should be a 9-bit signal or port.
but when I define Output as a 9-bit port, a warining comes up in synthesize
and an error comes up during simulating with ISIM (The simulator is stopped)
So what should I do to add two 8-bits and put it in a 9-bit signal or port?
2- My secend problem is with multiplying part.
I want to use the Output port right here but it should be 16-bit port.
first : i dont know the code or function that does this on std_logic_vector
secend : if I define output as a 16-bit port, I will be facing some other problems with adding part
Please help me, I am really confused
- - - Updated - - -
Hi Guys
I wrote a new code and it seems to work correctly
what do you think about this one
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
entity PocketCalculator is
Generic (Bits : integer := 8);
Port ( Input_1 : in STD_LOGIC_VECTOR (Bits-1 downto 0):=(Others =>'0');
Input_2 : in STD_LOGIC_VECTOR (Bits-1 downto 0):=(Others =>'0');
Select_Operator : in STD_LOGIC_VECTOR (2 downto 0):=(Others => '0');
Output : out STD_LOGIC_VECTOR ((2*Bits)-1 downto 0):=(Others =>'0'));
end PocketCalculator;
architecture Behavioral of PocketCalculator is
Signal Add_Result,Sub_Result : Std_logic_vector (Bits downto 0):= (Others=>'0');
Signal Mul_Result : Std_logic_vector ((2*Bits)-1 downto 0):= (Others=>'0');
begin
Add_Result <= ('0' & Input_1) + ('0' & Input_2);
Sub_Result <= ('0' & Input_1) + (not ('0' & Input_2)) + 1;
Mul_Result <= Input_1 * Input_2;
Output <= "0000000" & Add_Result when Select_Operator="100" else
std_logic_vector(resize(Signed(Sub_Result),16)) when Select_Operator="010" else
Mul_Result when Select_Operator="001" else
(Others =>'0');
end Behavioral;