Modelsim仿真——生成数据读取数据

需要产生100行16byte的数据,使用python产生,其中的"{0:0"+str(width)+“b}”).format(value),将value转换成二进制的字符串,长度是width,在前面自动补零

import random

def dict_to_binstr(dict):
    ret = ""
    for width, value in dict.items():
        ret = ret + ("{0:0"+str(width)+"b}").format(value)
    return ret

rsvd = 0
dword0 = 0
dword1 = 0

f = open("admin_data.txt", 'w+')

for i in range(100):
	sq_id = random.randint(0,4)
	p = random.randint(0,1)
	sq_head = i
	cid = i
	sq_head_pointer = i
	do_not_try = random.randint(0,1)
	more = random.randint(0,1)
	status_code_type = random.randint(0,7)
	if(i%2==0): 
		status_code = 0
	else :
		status_code = random.randint(0,127)		
	dict = {1:do_not_try,1:more,2:rsvd,3:status_code_type,8:status_code,
	1:p,16:cid,16:sq_id,16:sq_head_pointer,32:dword1,32:dword1}
	result = dict_to_binstr(dict)
	print(result,file = f)

Modelsim读取admin_data.txt文件的代码

    parameter wordsize = 127;
    parameter arraysize = 100;
    reg [wordsize:0] admin_cq_entry_table [0:arraysize];
    integer i;
    initial begin
    $readmemb("C:\\xxx\\admin_data.txt", admin_cq_entry_table);
    for(i = 0;i

用函数readmemb()读取二进制文件
注意在windows系统里,路径用绝对路径,且‘\’用‘\’代替

你可能感兴趣的:(Verilog)