SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module calcu16 (
  2.     input clk
  3. );
  4.     // Registers
  5.     reg [0:15] regArray [0:7]; // General Purpose
  6.     reg [0:15] pc = 0; // Program counter
  7.     reg [0:25] ir; // Instruction register
  8.  
  9.     // Memory
  10.     reg [0:25] memory [0:65535];
  11.  
  12.     reg [0:3] opcode;
  13.     reg [0:2] regSel1;
  14.     reg [0:2] regSel2;
  15.     reg [0:2] regSel3;
  16.     reg [0:15] immediate;
  17.  
  18.     reg [0:16] tmp;
  19.  
  20.     integer i;
  21.  
  22.     always @(posedge clk) begin
  23.         ir = memory[pc];
  24.  
  25.         opcode = ir[0:3];
  26.         regSel1 = ir[4:6];
  27.         regSel2 = ir[7:9];
  28.         regSel3 = ir[10:12];
  29.         immediate = ir[10:25];
  30.  
  31.         pc = pc + 1;
  32.        
  33.         case (opcode)
  34.             4'b0001: // ADD
  35.                 regArray[regSel1] = regArray[regSel2] + regArray[regSel3];
  36.             4'b0010: // ADDI
  37.                 regArray[regSel1] = regArray[regSel2] + immediate;
  38.             4'b0011: // JMP
  39.                 pc = immediate;
  40.             4'b0100: // JEQ
  41.                 pc = (regArray[regSel1] == regArray[regSel2]) ? immediate : pc;
  42.             4'b0101: // STORE
  43.                 memory[immediate + regArray[regSel2]] = regArray[regSel1];
  44.             4'b0110: // LOAD
  45.                 regArray[regSel1] = memory[immediate + regArray[regSel2]];
  46.             4'b0111: // XOR
  47.                 regArray[regSel1] = regArray[regSel2] ^ regArray[regSel3];
  48.             4'b1000: // AND
  49.                 regArray[regSel1] = regArray[regSel2] & regArray[regSel3];
  50.         endcase
  51.     end
  52.  
  53. endmodule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top