Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I understand that you can declare a string in a Verilog test bench as follows:
reg [8*14:1] string_value;
initial
string_value = "Hello, World!";
I can then do things with this string, like use $display
in a test bench to display it.
I haven't been successful in doing the same in a module when I flash it to my FPGA:
reg [8*14:1] string_value;
always @(reset)
begin
string_value = "Hello, World!";
// Do stuff with string value
Even assigning a single value does not work:
reg [8:1] char_value;
always @(reset)
begin
char_value = "A";
if (char_value == 8'h41)
// Do stuff!
I want to shift the individual characters on an 8-bit bus to an LCD screen for display.
How can I work with strings in Verilog?
–
–
–
–
You now have a constant with ASCII values in it that you can index into.
reg [7:0] data_out;
reg data_out_valid;
reg [3:0] some_index;
// pushing data onto a bus
data_out <= foo[some_index];
data_out_valid <= 1'd1;
some_index <= some_index + 4'd1;
With appropriate index checking and control that should work.
if (BIWEn==1'b1 ||BIREn==1'b1)
begin:START_STATE_WRITE
psW=idleW; //psW is Present State Write
string_value1= "IDLE";
![test bench] (c:\pictures)
–
SystemVerilog should support string assignment as mentioned in spec:
For example, to store the 12-character string "Hello world\n" requires a variable 8x12, or 96 bits wide.
bit [8*12:1] stringvar = "Hello world\n";
Not sure if the old verilog supports it or not.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.