Class Execution

java.lang.Object
io.matita08.logic.Execution

public class Execution extends Object
CPU Execution Engine - Instruction Cycle Management.

This class manages the CPU's instruction execution cycle, implementing the fetch-decode-execute paradigm. It coordinates instruction processing, memory access, and program counter management.

Key responsibilities:

  • Single-step and multi-step execution control
  • Instruction fetch from memory
  • Instruction decoding and operation lookup
  • Execution phase coordination
  • Memory access operations
  • Program counter advancement

Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    Flag indicating whether a step operation has been performed.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    DECODE Phase - Decodes the instruction and prepares for execution.
    static void
    EXECUTE Phase - Executes the decoded instruction.
    static void
    FETCH Phase - Retrieves the next instruction from memory.
    static Value
    Gets the next instruction address and increments the program counter.
    static void
    readPointer(int cycle)
    Reads address pointer data during multi-cycle instruction execution.
    static void
    Sets MAR and performs a memory read operation.
    static boolean
    Executes a single CPU instruction step.
    static void
    step(int countMax)
    Executes multiple CPU instruction steps up to the specified maximum.
    static void
    step(ActionEvent ignored)
    GUI event handler for single-step execution.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • stepped

      public static boolean stepped
      Flag indicating whether a step operation has been performed. Used for GUI update coordination and execution tracking.
  • Constructor Details

    • Execution

      public Execution()
  • Method Details

    • step

      public static void step(int countMax)
      Executes multiple CPU instruction steps up to the specified maximum.

      Continues executing CPU steps until either the maximum count is reached or the CPU enters a halted state (unable to step further).

      Parameters:
      countMax - the maximum number of steps to execute
    • step

      public static boolean step()
      Executes a single CPU instruction step.

      Advances the CPU through one phase of the instruction cycle (Fetch, Decode, or Execute). Handles halt conditions and coordinates GUI updates.

      Returns:
      true if the step was successful, false if CPU is halted
    • fetch

      public static void fetch()
      FETCH Phase - Retrieves the next instruction from memory.

      Performs the instruction fetch cycle:

      1. Clears ALU operation display
      2. Sets MAR to current PC value and increments PC
      3. Loads instruction from memory into IR
      4. Prepares for decode phase

    • decode

      public static void decode()
      DECODE Phase - Decodes the instruction and prepares for execution.

      Performs the instruction decode cycle:

      1. Looks up the operation based on IR contents
      2. Sets up cycle counts for the instruction
      3. Prepares for execute phase

    • execute

      public static void execute()
      EXECUTE Phase - Executes the decoded instruction.

      Performs the instruction execution cycle:

      1. Calls the instruction's execution logic for current cycle
      2. Handles multi-cycle instruction coordination
      3. Returns to fetch phase when execution completes

    • step

      public static void step(ActionEvent ignored)
      GUI event handler for single-step execution.

      ActionListener implementation for GUI step buttons. Executes a single CPU step in a background thread.

      Parameters:
      ignored - the ActionEvent (not used)
    • next

      public static Value next()
      Gets the next instruction address and increments the program counter.

      This atomic operation is crucial for proper instruction sequencing. Returns the current PC value and then increments it for the next instruction fetch.

      Returns:
      the current PC value before increment
    • setMarR

      public static void setMarR(Value v)
      Sets MAR and performs a memory read operation.

      Helper method that combines MAR setting with memory data retrieval:

      1. Sets the Memory Address Register to the specified value
      2. Reads the data from that memory location into MDR

      Parameters:
      v - the memory address to read from
    • readPointer

      public static void readPointer(int cycle)
      Reads address pointer data during multi-cycle instruction execution.

      This method handles the address reading phase of instructions that require memory address operands (like LOAD, STO, JPZ). It reads address components from consecutive memory locations and assembles them into the pointer register.

      Parameters:
      cycle - the current cycle number within the address reading phase
      Throws:
      AssertionError - if cycle number is out of valid bounds