Advertisement
Guest User

Untitled

a guest
Oct 7th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // full_machine: execute a series of MIPS instructions from an instruction cache
  2. //
  3. // except (output) - set to 1 when an unrecognized instruction is to be executed.
  4. // clock   (input) - the clock signal
  5. // reset   (input) - set to 1 to set all registers to zero, set to 0 for normal execution.
  6.  
  7. module full_machine(except, clock, reset);
  8.     output      except;
  9.     input       clock, reset;
  10.  
  11.     wire [31:0] inst;
  12.     wire [31:0] PC;
  13.     wire [31:0] nextPC, iPC, jPC, branch_offset, imm32;
  14.     wire rd_src, alu_src2, wr_enable;
  15.     wire [2:0] alu_op;
  16.     wire [4:0] Rdest;
  17.     wire [31:0] rd_Data, addr;
  18.     wire zero, negative, overflow;
  19.     wire dataOtI;
  20.     wire [1:0] control_type;
  21.     wire       mem_read, word_we, byte_we, byte_load, slt, lui, addm;
  22.     // ******** PC Register and Instruction Memory ******* //
  23.     // DO NOT comment out or rename this module
  24.     // or the test bench will break
  25.     register #(32) PC_reg(PC, nextPC, clock, 1'b1, reset);
  26.     alu32 alu(iPC, zero, negative, overflow, PC, 32'b0100, 3'b010);
  27.  
  28.     // DO NOT comment out or rename this module
  29.     // or the test bench will break
  30.     wire [31:0] rsData, rtData, B;
  31.     instruction_memory im(inst, PC[31:2]);
  32.     assign imm32 = { {16{inst[15]}}, inst[15:0] };
  33.     assign branch_offset = imm32 << 2;
  34.     alu32 alu1(jPC, zero, negative, overflow, iPC, branch_offset, 3'b010);
  35.  
  36.     // ************************************************** //
  37.     // ********** Register ************** //
  38.  
  39.     // DO NOT comment out or rename this module
  40.     // or the test bench will break
  41.     mips_decode mpd(alu_op, rd_src, alu_src2, wr_enable, except, control_type,
  42.                     mem_read, word_we, byte_we, byte_load, slt, lui, addm,
  43.                     inst[31:26], inst[5:0], zero);
  44.     mux4v #(32) nextPCMux(nextPC, iPC, jPC, { PC[31:28], {28{1'b0}}}, rsData,
  45.                                 control_type);
  46.     mux2v #(5)  m2(Rdest, inst[15:11], inst[20:16], rd_src);
  47.     regfile rf(rsData, rtData, inst[25:21], inst[20:16], Rdest, rd_Data,
  48.                 wr_enable, clock, reset);
  49.     //mux2v #(32) rdMux(rd_Data, {inst[15:0], 16'b0}, dataOtI, lui);
  50.     // ********** ********* ************** //
  51.     // ********** Data Memory ************ //
  52.     wire [31:0] data_out;
  53.     mux2v #(32) m2_1(B, rtData, imm32, alu_src2);
  54.     alu32 pDMALU(addr, zero, negative, overflow, rsData, B, alu_op);
  55.     data_mem dm(data_out, addr, rtData, word_we, byte_we, clock, reset);
  56.     /* add other modules */
  57.     // ********************************** //
  58.     // ********** Whole Lotta Mux's ******//
  59.     wire [7:0] riData8, riData132;
  60.     wire [31:0] riData232, riData332, riData3532;
  61.     mux4v #(8) oMux(riData132, data_out[31:24], data_out[23:16], data_out[15:8],
  62.                     data_out[7:0], addr[1:0]);
  63.     mux2v #(32) fMux(riData232, data_out, {24'b0, riData132}, byte_load);
  64.     mux2v #(32) gMux(riData3532, addr, {31'b0, negative}, slt);
  65.     mux2v #(32) mMux(riData332, riData3532, riData232, mem_read);
  66.     mux2v #(32) fmMux(rd_Data, riData332, {16'b0, inst[15:0]}, lui);
  67.  
  68. endmodule // full_machine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement