问题描述
我正在使用VHDL,我想知道是否有任何方法可以在初始化时使用字符串来限制字符串的大小。例如,我们声明如下字符串:
variable sequence : string(1 to 20) := "AGTAACCAATTCGCATTCGC";
我想知道是否有什么办法可以做:
variable sequence : string := "AGTAACCAATTCGCATTCGC";
当然,第二行是无效的,因为解释器说:
[VRFC 10-1547] variable cannot be unconstrained
解决方法
常量不必受约束,因此您可以这样做:
constant Csequence : string := "AGTAACCAATTCGCATTCGC";
variable Vsequence : string(Csequence'range) := Csequence;
https://www.edaplayground.com/x/r3wK
entity E is
end entity E;
architecture A of E is
begin
process
constant Csequence : string := "AGTAACCAATTCGCATTCGC";
variable Vsequence : string(Csequence'range) := Csequence;
begin
wait;
end process;
end architecture A;