mem8.v 2.38 KB
// This confidential and propriety software may be used
// only as authorized by a licensing agreement from
// Ocean Logic Pty Ltd http://www.ocean-logic.com
// 
// In the event of publication, the following notice is
// applicable
// 
// (C) COPYRIGHT 2001 Ocean Logic Pty Ltd
// ALL RIGHTS RESERVED
//
// the entire notice must be reproduced on all
// authorized copies
// 
// File : mem.vhd
// Author : Vincenzo Liguori
// Date : 01-03-02
// Version 1.0
// Abstract :
// This implements the AES key registers
// 
// Modification history :
// Date      by  Version  Change description
// -------------------------------------------------
// 01-03-02  VL   1.0     Original

module mem8(
clk,
rstn,
en,
we,
ar,
aw,
din,
dout
);

input clk, rstn;
input en, we;
input[2:0] ar, aw;
input[31:0] din;
output[31:0] dout;

wire   clk;
wire   rstn;
wire   en;
wire   we;
wire  [2:0] ar;
wire  [2:0] aw;
wire  [31:0] din;
reg  [31:0] dout;


reg [31:0] d0;
reg [31:0] d1;
reg [31:0] d2;
reg [31:0] d3;
reg [31:0] d4;
reg [31:0] d5;
reg [31:0] d6;
reg [31:0] d7;

  always @(ar or d0 or d1 or d2 or d3 or d4 or d5 or d6 or d7) begin
    case(ar)
      3'b 000 : dout <= d0;
      3'b 001 : dout <= d1;
      3'b 010 : dout <= d2;
      3'b 011 : dout <= d3;
      3'b 100 : dout <= d4;
      3'b 101 : dout <= d5;
      3'b 110 : dout <= d6;
      default : dout <= d7;
    endcase
  end

  always @(posedge clk or negedge rstn) begin
    if(rstn == 1'b 0) begin
      d0 <= {32{1'b0}};
      d1 <= {32{1'b0}};
      d2 <= {32{1'b0}};
      d3 <= {32{1'b0}};
      d4 <= {32{1'b0}};
      d5 <= {32{1'b0}};
      d6 <= {32{1'b0}};
      d7 <= {32{1'b0}};
    end else begin
      if(en == 1'b 1) begin
        if(we == 1'b 1) begin
          case(aw)
          3'b 000 : begin
            d0 <= din;
          end
          3'b 001 : begin
            d1 <= din;
          end
          3'b 010 : begin
            d2 <= din;
          end
          3'b 011 : begin
            d3 <= din;
          end
          3'b 100 : begin
            d4 <= din;
          end
          3'b 101 : begin
            d5 <= din;
          end
          3'b 110 : begin
            d6 <= din;
          end
          default : begin
            d7 <= din;
          end
          endcase
        end
      end
    end
  end


endmodule