EmbDev.net

Forum: FPGA, VHDL & Verilog Error in my program


von ayr (Guest)


Rate this post
useful
not useful
The entity shall implement the following arithmetic functionality:
• Substraction I1 - I2
• Input operand 1 (I1): 12 bit, two’s complement
• Input operand 2 (I2): 8 bit, two’s complement
• Output (O): 12 bit, two’s complement
• Overflow (V) and Carry flag (C) set accordingly
• Valid flag (VALID): indicates if the computed solution is valid or not

So what I have done?

Here is it:

library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.numeric_std.all;

entity arithmetic is

port( I1 :in std_logic_vector(12-1 downto 0); -- Operand 1

I2 :in std_logic_vector(8-1 downto 0); -- Operand 2

O :out std_logic_vector(12-1 downto 0); -- Output

C :out std_logic; -- Carry Flag

V :out std_logic; -- Overflow Flag

VALID :out std_logic -- Flag to indicate if the solution is valid or not

);

end arithmetic;

architecture behavior of arithmetic is

begin

process(I1,I2)

begin

if ((unsigned(I1)-unsigned(I2)) > unsigned(I1)) and 
((unsigned(I1)-unsigned(I2)) > unsigned(I2)) then

C <= '1';

else

C <= '0';

end if;

if I1(11)='1' and signed(std_logic_vector(unsigned(I1)-unsigned(I2)))>0 
then

V <= '1';

else

V <= '0';

end if;

if unsigned(I1) < unsigned(I2) then

VALID <= '0';

else

VALID <= '1';

end if;

O <= std_logic_vector(unsigned(I1)-unsigned(I2));

end process;

end behavior;


There is no syntax mistakes or something like that. Only mistake is 
that:

Error for:

comp2,SUB

I1= 100000011110

I2= 01000001

Expected:

O= 011111011101

C= '0', V= '1', VALID= '0'

Received:

O= 011111011101

C= '0', V= '1' and VALID= '1'


If someone could help I would be really thankful.

von ottonormaloser (Guest)


Rate this post
useful
not useful
I am times so free:
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use IEEE.numeric_std.all;
4
entity arithmetic is
5
port( I1 :in std_logic_vector(12-1 downto 0); -- Operand 1
6
I2 :in std_logic_vector(8-1 downto 0); -- Operand 2
7
O :out std_logic_vector(12-1 downto 0); -- Output
8
C :out std_logic; -- Carry Flag
9
V :out std_logic; -- Overflow Flag
10
VALID :out std_logic -- Flag to indicate if the solution is valid or not
11
);
12
end arithmetic;
architecture behavior of arithmetic is
1
begin
2
process(I1,I2)
3
begin
4
if ((unsigned(I1)-unsigned(I2)) > unsigned(I1)) and ((unsigned(I1)-unsigned(I2)) > unsigned(I2)) then
5
C <= '1';
6
else
7
C <= '0';
8
end if;
9
if I1(11)='1' and signed(std_logic_vector(unsigned(I1)-unsigned(I2)))>0 then
10
V <= '1';
11
else
12
V <= '0';
13
end if;
14
if unsigned(I1) < unsigned(I2) then
15
VALID <= '0';
16
else
17
VALID <= '1';
18
end if;
19
O <= std_logic_vector(unsigned(I1)-unsigned(I2));
20
end process;
21
end behavior;
There is no syntax mistakes or something like that. Only mistake is 
that:
1
Error for:
2
comp2,SUB
3
I1= 100000011110
4
I2= 01000001
5
Expected:
6
O= 011111011101
7
C= '0', V= '1', VALID= '0'
8
Received:
9
O= 011111011101
10
C= '0', V= '1' and VALID= '1'
If someone could help I would be really thankful.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
As an unsigned 100000011110 is 2078 and 01000001 is 64 the result you 
get is that whats written in the code:
1
if 2078 < 65 then 
2
   VALID <= '0';
3
else
4
   VALID <= '1'; 
5
end if;
So, the remaining question is: what did you want to achieve by that 
compare operation?

I would run the subtraction on 13 bit vectors (resize() both vectors to 
13 bit and perform the operation on those vectors) and then have a look 
how the both MSB behave.

von ayr (Guest)


Rate this post
useful
not useful
even when I put signed it's still mistake :/

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
ayr wrote:
> even when I put signed it's still mistake :/
What do you "put signed"?
What do you expect then and what happens instead?

von ayr (Guest)


Rate this post
useful
not useful
To get good valid correct

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.