Advertisement
Slapoguzov

Untitled

Nov 18th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module main(
  2.     input clk,
  3.     input com[31:0],
  4.     input t[31:0],
  5.     input op1[31:0],
  6.     input op2[31:0],
  7.     input rst,
  8.     output addr)
  9.    
  10.          //opcodes
  11.      localparam         BEQ   = 6'b000100,
  12.                     J     = 6'd2;
  13.      //--------------------------------
  14.    
  15.     wire next_addr[31:0];
  16.     wire cur_addr[31:0];
  17.     wire opcode[5:0] <= com[31:26];
  18.     wire sign_ext[31:0] <= com[15:0] ;
  19.     wire jmp_adr[24:0] = com[24:0];
  20.    
  21.     assign sign_ext = sign_ext << 16; //или на 2?
  22.    
  23.     ps ps_my(
  24.         .clk(clk),
  25.         .rst(rst),
  26.         .next_val(next_addr),
  27.         .addr(cur_addr)
  28.     );
  29.    
  30.     always@(posedge clk) begin
  31.         if(opcode == BEQ) begin
  32.             if(op1 == op2)
  33.                 next_addr = sign_ext + t;
  34.             else
  35.                 next_addr = cur_addr + 4;
  36.         end
  37.         else if (opcode == J) begin
  38.                 next_addr = (cur_addr & 8'hf0000000) | (jmp_adr << 2); //или на 16?
  39.         end
  40.         else begin
  41.                 next_addr = cur_addr + 4;
  42.         end
  43.    
  44.     end
  45.    
  46. endmodule
  47.  
  48. module ps(
  49.     input clk,
  50.     input rst,
  51.     input next_val[31:0],
  52.     output addr[31:0])
  53.    
  54.     always@(posedge clk,posedge rst) begin
  55.         if(rst)
  56.             addr<=0;
  57.         else
  58.             addr<=next_val;
  59.     end
  60. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement