Advertisement
MBJ

Instruction Memory

MBJ
Apr 22nd, 2019
1,742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. // in the IF phase of pipeline
  4. // emulates the codes being flashed into ROM part of microprocessor
  5.  
  6.  
  7. module Instruction_memory(
  8.                             input [31:0] PC,
  9.                             output reg [31:0] IR    // YESSSS!
  10.                             );
  11.  
  12.  
  13. reg [6:0] opcode = 0;
  14. reg [4:0] DA = 0;
  15. reg [4:0] AA = 0;
  16. reg [4:0] BA = 0;
  17. reg [9:0] junk = 0;
  18. reg [14:0] IM = 0;
  19. reg [14:0] TAR = 0;
  20.  
  21. localparam NOP = 7'b0000000;
  22. localparam ADD = 7'b0000010;
  23. localparam SUB = 7'b0000101;
  24. localparam SLT = 7'b1100101;
  25. localparam AND = 7'b0001000;
  26. localparam OR  = 7'b0001010;
  27. localparam XOR = 7'b0001100;
  28. localparam ST  = 7'b0000001;
  29. localparam LD  = 7'b0100001;
  30. localparam ADI = 7'b0100010;
  31. localparam SBI = 7'b0100101;
  32. localparam NOT = 7'b0101110;
  33. localparam ANI = 7'b0101000;
  34. localparam ORI = 7'b0101010;
  35. localparam XRI = 7'b0101100;
  36. localparam AIU = 7'b1100010;
  37. localparam SIU = 7'b1000101;
  38. localparam MOV = 7'b1000000;
  39. localparam LSL = 7'b0110000;
  40. localparam LSR = 7'b0110001;
  41. localparam JMR = 7'b1100001;
  42. localparam BZ  = 7'b0100000;
  43. localparam BNZ = 7'b1100000;
  44. localparam JMP = 7'b1000100;
  45. localparam JML = 7'b0000111;
  46.  
  47. // NO DATA FORWARDING FOR NOW, SO ADD NO OPS IN BETWEEN
  48.  
  49. //1, add sign IM, dest = R5, AA = 1, IM = 27
  50. //7-bits opcode, 5-bits dest, 5-bits sA, optional: 5-bit sB/10-junk, 15-bit immediate, 15-bit target jump
  51. // block of code to assign
  52.                 // 7-bits |5-bit |5-bit| 5-bit + 10-bit |
  53.                 // OPCODE | DEST | AA  | TARGET JUMP    |
  54. always@(*) begin// OPCODE | DEST | AA  | IMMEDIATE      |
  55.     case(PC)    // OPCODE | DEST | AA  | BA  | JUNK     |
  56.         0: IR = NOP;
  57.         1: IR = 32'b0100010_00101_00001_000000000011011; // 27 + R1 (0) --> R 5 {ADI,dest,aa,immediate}
  58.         2: IR = NOP;
  59.         3: IR = 32'b0101110_00100_00101_000000000011011; // NOT R5 --> R4 (immediate unused), {NOT,dest,aa,immediate unused}
  60.         4: IR = NOP;
  61.         5: IR = 32'b0101110_00011_00000_000000000011011; // NOT R0 --> R3 {NOT,dest,aa,immediate unused}
  62.         6: IR = NOP;
  63.         7: IR = 32'b0000001_00000_00101_001000000011011; // Store R4 -->M(R5) {}
  64.         8: IR = NOP;
  65.         9: IR = 32'b0100001_00110_00101_000000000011011;    // load M(R5) --> R6
  66.         10:IR = NOP;
  67.         11:IR = 32'b0100000_00101_00000_100000000001100; // do a jump here BZ (R(A)) = 0 --> PC + 1 +se IM (PC + 1 = 12, + se 12 (MSB = 1, so negative))
  68.             // should have the PC increment, then subtract back to 0
  69.         default: IR = NOP;
  70.     endcase
  71.    
  72. end
  73.  
  74. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement