function to_bcd ( bin :std_logic_vector(7downto0))returnstd_logic_vectorisvariable i :integer:=0;variable bcd :std_logic_vector(11downto0):=(others=> '0');variable bint :std_logic_vector(7downto0):= bin;beginfor i in0to7loop-- repeating 8 times.
bcd(11downto1):= bcd(10downto0);--shifting the bits.
bcd(0):= bint(7);
bint(7downto1):= bint(6downto0);
bint(0):='0';if(i <7and bcd(3downto0)>"0100")then--add 3 if BCD digit is greater than 4.
bcd(3downto0):= bcd(3downto0)+"0011";endif;if(i <7and bcd(7downto4)>"0100")then--add 3 if BCD digit is greater than 4.
bcd(7downto4):= bcd(7downto4)+"0011";endif;if(i <7and bcd(11downto8)>"0100")then--add 3 if BCD digit is greater than 4.
bcd(11downto8):= bcd(11downto8)+"0011";endif;endloop;return bcd;end to_bcd
What's you particularly question? I see, that you have been able to copy the popular "double dabble" code from the internet. (Reference in https://en.wikipedia.org/wiki/Double_dabble)
As far as I see, it's a syntactically correct VHDL function. I assume, it will serve it's purpose.
P.S.:
In addition, you would want to add a standard package header (I guess, you'll find a template in your favourite VHDL text book).
Code:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
package my_bcd is
function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector;
end package;
package body my_bcd is
-- your code
end package body my_bcd;