HOME VHDL CODES C PROGRAMS SOCCER BUZzz TECH INFO

Showing posts with label ones. Show all posts
Showing posts with label ones. Show all posts


--code for counting no of 1's using loop method:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity onesusingloop is
 port(d:in std_logic_vector(9 downto 0);
 count:out integer);
 end onesusingloop;

 architecture beh of onesusingloop is
 begin
 process(d)
 variable x:integer;
 begin
 x:=0;
 for i in 0 to 9 loop
 if(d(i)='1')then
 x:=x+1;
 end if;
 end loop;
 count<=x;
 end process;
 end beh;

The above code has been executed and has been found to have no errors..!  
plz do comment..!
thank u..!! :) :)

--vhdl code to count number of 1's using behavioral:


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity one_counter is
port(a:in std_logic_vector(9 downto 0);
count:out integer);
end one_counter; 
architecture Behavioral of one_counter is
begin

process(a)
variable c: integer;
begin
c:=0;
a1:for i in 0 to 9 loop
if(a(i)='1')then
c:=c+1;
end if; 
end loop a1;
count<=c;
end process;
end Behavioral;

The above code has been executed and has been found to have no errors..!  plz do comment..!
thank u..!! :) :)
  

Total Pageviews

About this blog

Contributors

Followers

Powered by Blogger.

Labels