Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Brian Chan
  2. //Jason Li
  3. //Worked together with 4-member lab group (Helen Xu and Maria Mancz) in lab period
  4.  
  5. //IF
  6. module IF (PC, instructions);
  7.     input PC;
  8.     input instructions;
  9.     output instructreg;
  10.    
  11.     assign instructreg <= instructions[PC/4];
  12. endmodule
  13.  
  14. //ID
  15. module ID1(instruction, r1, r2, regwrite, wd);
  16.     input instruction;
  17.     output[5:0] opcode, funct;
  18.     output[4:0] rs, rt, rd, shamt;
  19.     wire[15:0] imm;
  20.     output [31:0] imm2;
  21.     output[25:0] addr;
  22.     output branch_pcval;
  23.     input[4:0] r1, r2; //read reg 1 + 2
  24.     output[31:0] rd1, rd2; //read data 1 + 2
  25.     input regwrite;
  26.     input wd; //write data
  27.        
  28.     assign opcode <= instruction[30:25];
  29.    
  30.     if(opcode == 0)begin
  31.         assign rs <= instruction[25:21];
  32.         assign rt <= instruction[20:16];
  33.         assign rd = instruction[15:11];
  34.         assign shamt = instruction[10:6];
  35.         assign funct = instruction[5:0];//R types
  36.     end
  37.     else begin
  38.         assign rs <= instruction[25:21];
  39.         assign rt <= instruction[20:16];
  40.         assign imm <= instruction[15:0];
  41.         //I types
  42.        
  43.     branch_pcval = instruction-imm;//if it is a branch instruction, calculate branch value
  44.     end
  45.  
  46.    
  47.     always @(posedge clk) begin
  48.         rd1 = register[r1];
  49.         rd2 = register[r2];
  50.         if(imm[15] == 0) begin
  51.             imm2 = imm;
  52.         end
  53.         else begin
  54.             imm2 = [16'hFFFF, imm];
  55.         end
  56.         //if immediate is only 16 bits, extend to 32 bits
  57.     end
  58.    
  59.     always @(*) begin
  60.         if (regwrite) begin
  61.             //change value in register if regwrite is 1
  62.         end  //for write back
  63.     end
  64.   end
  65.  
  66. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement