0
0
Verilogprogramming~10 mins

Memory initialization with $readmemh in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a memory array of 8-bit words with 256 entries.

Verilog
reg [7:0] memory [0:[1]];
Drag options to blanks, or click blank then click option'
A256
B128
C512
D255
Attempts:
3 left
💡 Hint
Common Mistakes
Using 256 as the highest index instead of 255.
2fill in blank
medium

Complete the code to initialize the memory from a hex file named 'data.hex' inside an initial block.

Verilog
initial begin
  $readmemh([1], memory);
end
Drag options to blanks, or click blank then click option'
Adata.hex
B"data.hex"
C'data.hex'
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes or using single quotes around the filename.
3fill in blank
hard

Fix the error in the code to correctly initialize the memory using $readmemh.

Verilog
initial begin
  $readmemh("data.hex", [1]);
end
Drag options to blanks, or click blank then click option'
Amem_array
Bmem
Cmemory
Dmemdata
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not match the declared memory array.
4fill in blank
hard

Fill both blanks to create a memory initialization that reads from 'init.hex' and has 128 entries.

Verilog
reg [7:0] mem [0:[1]];
initial begin
  $readmemh([2], mem);
end
Drag options to blanks, or click blank then click option'
A127
B128
C"init.hex"
D'init.hex'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 128 as highest index or single quotes for filename.
5fill in blank
hard

Fill all three blanks to declare a 16-bit wide memory with 64 entries and initialize it from 'memdata.hex'.

Verilog
reg [[1]:0] mem_array [0:[2]];
initial begin
  $readmemh([3], mem_array);
end
Drag options to blanks, or click blank then click option'
A15
B63
C"memdata.hex"
D64
Attempts:
3 left
💡 Hint
Common Mistakes
Using 64 as highest index or missing quotes on filename.