Question

Instructions: For all the questions you are required to submit VHDL codes & test bench simulation screenshot. If anything els

Please answer both questions

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

entity reg16 is
   port (   clk, reset, inc   : in std_logic;
       load       : in std_logic;
       data_in       : in std_logic_vector (15 downto 0);
       q       : out std_logic_vector (15 downto 0)
   );
end reg16;

architecture arch of reg16 is

signal qreg : std_logic_vector (15 downto 0);

begin

process (clk, reset)

begin

   if (reset = '0') then

       qreg <= X"0000";

   else

       if rising_edge(clk) then

           if (load = '1') then

               qreg <= data_in;

            else

               if (inc = '1') then

                   qreg <= qreg + '1';

               end if;

           end if;

       end if;

   end if;

   q <= qreg;

end process;

end arch;

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

Wave File Edit View Add Format Tools Bookmarks Window Help Wave -Default Msgs freg16/ck freg 16freset reg 16 nc reg 16/oed fr

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

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity vector is
   generic (length : natural := 8);
   port (   data_in       : in std_logic_vector (length downto 1);
       dout       : out std_logic_vector (length downto 1)
   );
end vector;

architecture arch of vector is

begin

process (data_in)

variable reg : std_logic_vector (length downto 1);

begin
   reg := (others=>'0');

   for i in 1 to length loop

       if (data_in(i) = '1') then

           reg := '1' & reg(length downto 2);
       end if;

   end loop;

dout <= reg;
      
end process;

end arch;


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

Wave 0 File Edit View Add Format Tools Bookmarks Window Help Wave -Default Msgs vector fdata _in 00000001 400 0 ps to 420 ps

Add a comment
Know the answer?
Add Answer to:
Instructions: For all the questions you are required to submit VHDL codes & test bench simulation...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT