quwstion from newbie

Joined
May 22, 2007
Messages
2
Reaction score
0
Hi!
can u explain what this line do

result <= ('0' & A)+('0' & B);

esp this '0' thing

thanks


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

--------------------------------------------------------

entity ADDER is

generic(n: natural :=2);
port( A: in std_logic_vector(n-1 downto 0);
B: in std_logic_vector(n-1 downto 0);
carry: out std_logic;
sum: out std_logic_vector(n-1 downto 0)
);

end ADDER;

--------------------------------------------------------

architecture behv of ADDER is

-- define a temparary signal to store the result

signal result: std_logic_vector(n downto 0);

begin

-- the 3rd bit should be carry

result <= ('0' & A)+('0' & B);
sum <= result(n-1 downto 0);
carry <= result(n);

end behv;
 
Joined
May 22, 2007
Messages
2
Reaction score
0
Since the answer is one bit more than the inputs. If the '0' wouldn´t be there the carry would be lost. You can´t add two vectors of size x and get a result of size x+1. So the two input vectors have to extended with the most significant bit.
The vectors are unsigned, that´s important. If a and b are signed it should be a(MSB) & a + b(MSB) & b.

I hope this explains some.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top