Advertisement
MBJ

Register File

MBJ
Apr 22nd, 2019
1,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. // (DECODED OPERAND FETCH | WRITEBACK) = phases of the pipeline referenced in
  4.  
  5. // clock and reset to all regesters
  6. module Register_file(
  7.                     input clk, RW, rst,
  8.                     input [4:0] DA, AA, BA, // destination address (for writing to a register), A_address, B_address (busses used in datapath)
  9.                     input [31:0] D_DATA, // end of datapath, into register file
  10.                     output reg [31:0] A_DATA, B_DATA // corresponds to AA and BA
  11.                     );
  12. // REGISTER FILE: 32x32
  13.  
  14. reg [31:0] REGISTER [31:0]; // R0 always 0, or rather REGISTER[31:0][0] = 0;
  15. // what does 32 by 32 mean? 32--32-bit registers, 5 bits count from 0-31
  16.  
  17. // UPDATE: changed from [31:0] register [4:0] to [31:0] register [31:0]
  18. //          apparently, although addresses are 5 bit to account for 32 different addresses, the second length needs each own bit
  19.  
  20. integer i;
  21.  
  22. initial begin // initialize register block to 0
  23.     for(i = 0; i < 32; i = i + 1) begin
  24.         REGISTER[i] = 0;
  25.     end
  26. end
  27. // reading: Potentially reads up to two registers, for bus A and bus B
  28. // DOF phase
  29. always@(*) begin    // asynchronous parts, reading the registers
  30.     A_DATA = REGISTER[AA];
  31.     B_DATA = REGISTER[BA];
  32. end
  33. // WB phase
  34. always@(posedge clk, posedge rst) begin     // synchornous parts, writing to register
  35.     REGISTER[DA] <= ((RW) && (DA == 0))? 0 :            // R0 is ALWAYS 0
  36.                     (RW)? D_DATA : REGISTER[DA];    // if Read write bit is true, then alter the specified register, else don't change anything
  37.     if(rst) begin
  38.             for(i = 0; i < 32; i = i +1) begin
  39.                 REGISTER[i] = 0;
  40.             end
  41.     end
  42. end
  43.  
  44. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement