Perrine

MIPS Fetch

Nov 26th, 2012
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module fetch(clk, PC_src, immediate, instru, new_pc);
  2.     input clk, PC_src, immediate;
  3.     output instru, new_pc;
  4.    
  5.     //input
  6.     wire clk, PC_src;
  7.     wire[31:0] immediate;
  8.    
  9.     //output
  10.     reg[31:0] instru, new_pc;
  11.    
  12.     //internal
  13.     reg[31:0] pc, instru_mem[14:0];
  14.     integer i;
  15.    
  16.    
  17.     initial begin
  18.         pc = -4;
  19.         i = 0;
  20.        
  21.         for(i = 0; i < 15; i = i + 1) begin
  22.             instru_mem[i] = 0;
  23.         end
  24.     end
  25.    
  26.     always@(posedge clk) begin
  27.         if(PC_src == 1) begin
  28.             pc = immediate;
  29.         end else begin
  30.             pc = pc + 4;
  31.         end
  32.     end
  33.    
  34.     always@(negedge clk) begin
  35.         new_pc = pc;
  36.         instru = instru_mem[pc];
  37.     end
  38. endmodule
Advertisement