anhnha
Full Member level 6
![Full Member level 6](/styles/images/ranks/flevel3.gif)
Hi all,
I am learning verilog and this is a module used for read a character:
I have a problem in understanding the code, hope anyone can help me out.
1) Why we need wide_char[15:0] and why signed? A character is only one byte(8 bits)
2) What is reg [639:0] err_str is used for? And why here is [639:0], where it come from?
Thank you.
I am learning verilog and this is a module used for read a character:
Code:
module file_read()
parameter EOF = -1;
integer file_handle,error,indx;
reg signed [15:0] wide_char;
reg [7:0] mem[0:255];
reg [639:0] err_str;
initial begin
indx=0;
file_handle = $fopen(“text.txt”,”r”);
error = $ferror(file_handle,err_str);
if (error==0) begin
wide_char = 16’h0000;
while (wide_char!=EOF) begin
wide_char = $fgetc(file_handle);
mem[indx] = wide_char[7:0];
$write(“%c”,mem[indx]);
indx = indx + 1;
end
end
else $display(“Can’t open file…”);
$fclose(file_handle);
end
endmodule
1) Why we need wide_char[15:0] and why signed? A character is only one byte(8 bits)
2) What is reg [639:0] err_str is used for? And why here is [639:0], where it come from?
Thank you.