~ruther/verilog-riscv-semestral-project

ref: e7b5d989532b0690f2b0ef3a1b7a0072903c0d51 verilog-riscv-semestral-project/src/ram.sv -rwxr-xr-x 498 bytes
e7b5d989 — Rutherther test: add cpu testbenches for c programs 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cpu_types::*;

module ram (
  input         clk, we,
  input [31:0]  a, wd,
  input         memory_mask_t mask,
  output [31:0] rd);

  reg [4095:0]    RAM;

  assign rd = RAM[(a[11:0] * 8) +:32]; // word aligned

  always @(posedge clk)
    if(we) begin
      case(mask)
        MEM_BYTE: RAM[(a[11:0] * 8) +:8] <= wd[7:0];
        MEM_HALFWORD: RAM[(a[11:0] * 8) +:16] <= wd[15:0];
        MEM_WORD: RAM[(a[11:0] * 8) +:32] <= wd[31:0];
        default: ;
      endcase
    end

endmodule
Do not follow this link