`timescale 1ns/1ps module core_tb(); initial $timeformat(-9, 2, " ns", 20); initial begin: dump integer i; $dumpfile("core_tb.vcd"); $dumpvars(0, core_tb); for (i=0; i<32; i=i+1) begin $dumpvars(0, dut.regfile[i]); end end wire dummy_out; localparam MEM_ROM_LENGTH = 2048 >> 2; // words localparam MEM_LENGTH = MEM_ROM_LENGTH + 2048 >> 2; // words localparam MEM_DATA_BASE = 32'h00000800; localparam INST_NOP = 32'h00000013; // nop localparam DATA_DEFAULT = 32'h00000000; localparam DATA_INVALID = 32'hdeadbeef; reg clk, reset; // Instruction memory reg [31:0] mem [0:MEM_LENGTH-1]; wire [31:0] mem_inst_addr; wire [31:0] mem_inst_idx = mem_inst_addr >> 2; wire [31:0] mem_inst_data = mem_inst_idx < MEM_LENGTH ? mem[mem_inst_idx] : INST_NOP; initial begin: mem_init // integer i; // for (i=0; i> 2; always @(*) begin if (mem_data_idx < MEM_LENGTH) begin mem_data_rdata = mem[mem_data_idx]; end else begin mem_data_rdata = DATA_INVALID; end end always @(posedge clk) begin if (mem_data_idx < MEM_LENGTH && mem_data_idx >= MEM_ROM_LENGTH) begin if (mem_data_we) begin if (mem_data_wmask[0]) begin mem[mem_data_idx][7:0] <= mem_data_wdata[7:0]; end if (mem_data_wmask[1]) begin mem[mem_data_idx][15:8] <= mem_data_wdata[15:8]; end if (mem_data_wmask[2]) begin mem[mem_data_idx][23:16] <= mem_data_wdata[23:16]; end if (mem_data_wmask[3]) begin mem[mem_data_idx][31:24] <= mem_data_wdata[31:24]; end end end else begin // ignore illegal writes end end endmodule