How are string operands stored as constant numbers in a reg variable?
How are string operands stored as constant numbers in a reg variable?
Model answer
Strings are stored as ASCII characters in 8 bit fields. For example, the ASCII characters for lower case a-z are 8'h61 to 8'h7a. Hence, the reg declaration that uses these fields needs to accommodate the correct number of bits with 8 bits for each character. Since the ascii characters are stored as 8 bit fields, modifying these bits would change the value being displayed. The following example illustrates this. SystemVerilog allows the definition of variables as string. This is a very flexible mechanism of not only initialising these variables with a dynamically allocated array of characters, but also includes a set of associated functions which return the length of the string, character manipulation, case conversion etc.