# Formatting memory input file

**URL:** <https://verificationacademy.com/forums/t/formatting-memory-input-file/38705>\
**Category:** UVM\
**Tags:** UVM, readmemh\
**Created:** [February 10, 2021, 6:07pm UTC](https://verificationacademy.com/forums/t/formatting-memory-input-file/38705 "2021-02-10T18:07:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![n347](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/9de0a6/32.png) [@n347](https://verificationacademy.com/forums/u/n347)\
**Post date:** [February 10, 2021, 6:07pm UTC](https://verificationacademy.com/forums/t/formatting-memory-input-file/38705/1 "2021-02-10T18:07:22Z")

</div>

Any inputs/ideas on how to divide the below input file based on wr\_data width (WR\_DATA\_WIDTH =64/72/32), the below file shows the wr\_data starting at memory address 2 , BUT the data has to be divided based on the WR\_DATA\_WIDTH parameter and after that output few UVM memory calls to write to the address (offset calculated from the data\_width)…

Input file: readmemh format file

@2  
feef25fffff557edddcabdcbaaff7edddcabdcbaafffffff557eddcbaaff7edddcabdcbaafffffff557eddcbaaff7edddcabdcbaafffffff557edfeef25fffff557edddcabdcbaaff7edddca

Output should be below calls, mem.write (address,data) assuming WR\_DATA\_WIDTH =64

```auto
mem.write (2,feef25fffff557ed)
mem.write (3,ddcabdcbaaff7edd)

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [February 12, 2021, 7:24pm UTC](https://verificationacademy.com/forums/t/formatting-memory-input-file/38705/2 "2021-02-12T19:24:32Z")

</div>

_In reply to [n347](https://verificationacademy.com/forums/t/formatting-memory-input-file/38705):_

There a two ways I can think of to accomplish this. You can use $readmemh to read the file into a fixed width memory. You would know which addresses were not written to because they would still be X’s. Or you could parse the file yourself with $fscanf.

Either way you will wind up with a very large word (I’m not going to count the bits) and you’ll have to use a for loop to select the bits from the word

```verilog
logic [0:big_word_size] wr_data];

for (int i=0;i*WR_DATA_SIZE<big_word_size;i++)
    mem.write(starting_address+i,wr_data[i*WR_DATA_SIZE+:WR_DATA_SIZE]);

```
