I'm getting the following error " Line 44: "Syntax error near "If"." and something similar in lines 65, 67, 69, 73 (except with some "Else"s and other "If"s).
It's probably a very silly question, but could anyone help? :)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Four_Bit_Adder_Decimal_Output is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
Cin : in STD_LOGIC;
Res : out STD_LOGIC_VECTOR (4 downto 0);
Cout : out STD_LOGIC;
Dsp : out STD_LOGIC_VECTOR (3 downto 0);
Seg : out STD_LOGIC_VECTOR (6 downto 0));
end Four_Bit_Adder_Decimal_Output;
architecture Four_Bit_Adder_Decimal_Output_Arch of Four_Bit_Adder_Decimal_Output is
--Embedded signals
signal Tmp : STD_LOGIC_VECTOR (4 downto 0);
begin
--Display Selection
Dsp <= "0111";
--Check if any of the 4-bit inputs are bigger than 9
If ((A < 9) and (B < 9)) = '1' Then
Tmp <= ("00000" & A) + (B & "00000") + ("00000" & Cin);
Res <= Tmp;
Cout <= Tmp(4);
--Output must be in decimal, so you print the first digit in the display
seg <= "1000000" when (Tmp = X"0") else
"1111001" when (Tmp = X"1") else
"0100100" when (Tmp = X"2") else
"0110000" when (Tmp = X"3") else
"0011001" when (Tmp = X"4") else
"0010010" when (Tmp = X"5") else
"0000010" when (Tmp = X"6") else
"1111000" when (Tmp = X"7") else
"0000000" when (Tmp = X"8") else
"0010000" when (Tmp = X"9") else
"1000000" when (Tmp = X"A") else
"1111001" when (Tmp = X"B") else
"0100100" when (Tmp = X"C") else
"0011001" when (Tmp = X"D") else
"0010010" when (Tmp = X"F");
--Check if result has 2 digits, then turn ON Cout
If (Tmp >= 10) Then
Cout <= '1';
Else
Cout <= '0';
End If;
Else -- If any of the inputs is bigger than 9, throw an error
--Put "E" in the display
Seg <= "0000110";
End If;
end Four_Bit_Adder_Decimal_Output_Arch;
An if-statement is always used as a sequential statement. You'd find sequential statements in places such as processes or subprograms (functions / procedures).
architecture Four_Bit_Adder_Decimal_Output_Arch of Four_Bit_Adder_Decimal_Output is
...
begin
...
process(all) is begin
if ((A < 9) and (B < 9)) = '1' then
...
end if;
end process;
end architecture Four_Bit_Adder_Decimal_Output_Arch;
-daniel