Esempio n. 1
0
  /** Memory Access - Stage 4 */
  public static void stage4_memory() throws IOException {
    String binary_rep = pad_binary(Integer.toBinaryString(cpu.IR), 32);
    String op_code = (String) binary_rep.subSequence(binary_rep.length() - 6, binary_rep.length());

    if (cpu.c_mux_Y_select == 0) // If mux_Y is 0, use value from ALU (RZ)
    {
      cpu.RY = cpu.RZ;
    } else if (cpu.c_mux_Y_select == 1) // If mux_Y is set to 1, then must use memory
    {
      if (op_code.equals(definitions.STW)) // If the instruction is a STW (store)
      {
        pmi.memory_address = cpu.RZ; // memory address = RZ
        pmi.memory_data = cpu.RM; // memory data = RM
        mem = pmi.write_word(mem); // write memory
      } else if (op_code.equals(definitions.LDW)) // If the instruction is a LDW (load)
      {
        pmi.memory_address = cpu.RZ; // Memory address = RZ
        pmi.read_memory(file); // Read memory
        cpu.RY = PMI.memory_data; // RY = memory data
      }
    } else if (cpu.c_mux_Y_select == 2) // PC-Temp (Not required for this assignment)
    {

    }
  }
Esempio n. 2
0
 /** Instruction Fetch - Stage 1 */
 public static void stage1_fetch() throws IOException {
   pmi.memory_address = cpu.R[15]; // memory address = PC
   pmi.read_memory(file); // read memory (make a method)
   cpu.IR = pmi.memory_data; // IR = memory data
   cpu.R[15] = cpu.R[15] + 4; // pc = pc + 4
 }