Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read a hex file into memory using $readmemh.
Verilog
initial begin
$readmemh([1], memory_array);
endAttempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the filename in quotes.
Using single quotes instead of double quotes.
✗ Incorrect
The $readmemh system task requires the filename as a string in double quotes.
2fill in blank
mediumComplete the code to write the memory contents to a hex file using $writememh.
Verilog
initial begin
$writememh([1], memory_array);
endAttempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the filename.
Using single quotes instead of double quotes.
✗ Incorrect
The $writememh system task requires the filename as a string in double quotes.
3fill in blank
hardFix the error in the code to correctly read a hex file into a memory array.
Verilog
reg [7:0] mem [0:15]; initial begin $readmemh([1], mem); end
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted filename causing syntax error.
Using single quotes instead of double quotes.
✗ Incorrect
The filename must be a string in double quotes for $readmemh to work correctly.
4fill in blank
hardFill both blanks to read a hex file and write the memory contents back to another file.
Verilog
reg [15:0] mem_array [0:31]; initial begin $readmemh([1], mem_array); $writememh([2], mem_array); end
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting filenames.
Mixing quoted and unquoted filenames.
✗ Incorrect
Both $readmemh and $writememh require filenames as strings in double quotes.
5fill in blank
hardFill all three blanks to read a hex file, modify memory, and write it back.
Verilog
reg [7:0] mem [0:7]; integer i; initial begin $readmemh([1], mem); for (i = 0; i < 8; i = i + 1) begin mem[i] = mem[i] [2] 1; end $writememh([3], mem); end
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' for increment.
Not quoting filenames.
✗ Incorrect
Use double quotes for filenames and '+' to increment each memory element by 1.
