I'm not quite certain to understand what you are trying to do here. Maybe there is a bit of a XY problem in the first place. Nonetheless, I'll try to answer questions we have so far.
Strings are defined by standard as:
type STRING is array (POSITIVE range <>) of CHARACTER;
positive is defined as:
subtype POSITIVE is INTEGER range 1 to INTEGER'HIGH;
That's why you cannot use index 0: by definition,
string indices are from 1 onwards. When declaring variables/signals/subtypes, you may only be more restrictive than the original range.
In VHDL, strings are no more than arrays, the very same way
std_logic_vectors are arrays. You should think about assign strings the same way you do when assigning (part of) logic arrays.
Here in your example code, you seem to want to assign a variable-length string literal to a (constrained) string variable. You do it with a procedure that pads the input argument. You could as well create a function, which may be clearer:
function padded(s: string; len: positive := 64; p: character := ' ') return string
alias xs: string(1 to s'length) is s;
variable ret : string(1 to len) := (others => p);
if xs'length >= len then
ret := xs(1 to len);
ret(1 to xs'length) := xs;
variable str : string(1 to 64);
str := padded("hello world", str'length);
Another option is to use
access to a
Access is VHDL equivalent of pointers, with the nice feature that actual array constraints are attached to the targetted instance, so they may change.
It happens standard defines such thing in std.textio,
line, which is defined as:
type LINE is access STRING;
Line type definition comes with procedures that are able to append text to it, called
procedure WRITE (L: inout LINE; VALUE: in STRING;
JUSTIFIED: in SIDE:= RIGHT; FIELD: in WIDTH := 0);
write is overloaded for many other
value types, but I wont include them here, see standard for more.
L argument is
inout. It is actually modified by the procedure. Behind the scenes,
write reallocates the targetted
string object to new size.
Typical usage is for constructing variable-length message:
function describe_number(v: in integer) return string is
variable ret: line := new string'("");
write(ret, string'("Passed argument is: "));
if v >= 1000 then
write(ret, string'(", this is a lot !"));
end function describe_number;