import random total_count = random.randint(5, 50) # total_count = 20 total_count = 47 numbers = list() for _ in range(total_count): numbers.append(random.randint(0, 65535)) # numbers = [ # 0x4B8D, # 0x2307, # 0xFAE0, # 0x7815, # 0xC105, # 0x84F0, # 0xDB6, # 0xF21D, # 0xE97A, # 0xA3B6, # 0x8466, # 0x3A25, # 0x5DF, # 0xD2DE, # 0xBA7A, # 0x7809, # 0xF6A8, # 0x361D, # 0x3ADB, # 0x969A, # ] numbers = [ 0x022C, 0x0AA4, 0x0E87, 0x0F95, 0x124C, 0x18D0, 0x1A04, 0x1C49, 0x2137, 0x2197, 0x260B, 0x2CC7, 0x2E07, 0x2F2B, 0x3A27, 0x3B9F, 0x4227, 0x4786, 0x5E55, 0x5F99, 0x64CA, 0x6E15, 0x7345, 0x76EE, 0x7F32, 0x8027, 0x80BE, 0x9213, 0x9477, 0x9776, 0x9D7D, 0x9F23, 0xA5E5, 0xAA22, 0xAAF5, 0xABB3, 0xC308, 0xC5A5, 0xC8C3, 0xC94D, 0xD87C, 0xD9CA, 0xE060, 0xE08B, 0xE0D8, 0xE996, 0xF7FE, ] with open("gen_num.txt", "w") as fl: fl.writelines(["0x%04X\n" % x for x in numbers]) with open("gen_num_asm.txt", "w") as fl: fl.write( """lui $s0, 0x4000\naddi $s0, $s0, 0x60\naddi $s1, $zero, %d\nsw $s1, 0($s0)\n""" % (total_count) ) for idx, num in enumerate(numbers): fl.write("addi $s1, $zero, %s\nsw $s1, %d($s0)\n" % (hex(num), 4 * (idx + 1))) with open("gen_num_data_mem.txt", "w") as fl: fl.write( """for (i = StartAddressInWord; i < 24 + StartAddressInWord; i = i + 1) begin memory_data[i] <= 32'h00000000; end for ( i = %d + StartAddressInWord; i < MEM_SIZE_IN_WORD + StartAddressInWord; i = i + 1 ) begin memory_data[i] <= 32'h00000000; end """ % (24 + total_count + 1) ) fl.write("memory_data[StartAddressInWord + 24] <= 32'h%08X;\n" % total_count) for idx, num in enumerate(numbers): fl.write( "memory_data[StartAddressInWord + %d] <= 32'h%08X;\n" % (idx + 25, num) ) with open("gen_num_sorted.txt", "w") as fl: fl.writelines(["0x%04X\n" % x for x in sorted(numbers)])