Package mars.tools

Class InstructionStatistics

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, Memory.Listener, MarsTool

public class InstructionStatistics extends AbstractMarsTool
A MARS tool for obtaining instruction statistics by instruction category.

The code of this tools is initially based on the InstructionCounter tool by Felipe Lessa.

Author:
Ingo Kofler (ingo.kofler@itec.uni-klu.ac.at)
See Also:
  • Field Details

    • lastAddress

      protected int lastAddress
      The last address we saw. We ignore it because the only way for a program to execute twice the same instruction is to enter an infinite loop, which is not insteresting in the POV of counting instructions.
  • Constructor Details

    • InstructionStatistics

      public InstructionStatistics()
      Construct an instance of this tool. This will be used by the ToolManager.
  • Method Details

    • getName

      public String getName()
      returns the name of the tool
      Specified by:
      getName in interface MarsTool
      Specified by:
      getName in class AbstractMarsTool
      Returns:
      the tools's name
    • buildMainDisplayArea

      protected JComponent buildMainDisplayArea()
      creates the display area for the tool as required by the API
      Specified by:
      buildMainDisplayArea in class AbstractMarsTool
      Returns:
      a panel that holds the GUI of the tool
    • startObserving

      protected void startObserving()
      registers the tool as observer for the text segment of the MIPS program
      Overrides:
      startObserving in class AbstractMarsTool
      See Also:
    • stopObserving

      protected void stopObserving()
      Description copied from class: AbstractMarsTool
      Unregister this tool as a listener of memory and/or registers, if applicable. This method is called when the tool is closed by the user. Does nothing by default.
      Overrides:
      stopObserving in class AbstractMarsTool
      See Also:
    • getInstructionCategory

      protected int getInstructionCategory(BasicStatement stmt)
      decodes the instruction and determines the category of the instruction.

      The instruction is decoded by extracting the operation and function code of the 32-bit instruction. Only the most relevant instructions are decoded and categorized.

      Parameters:
      stmt - the instruction to decode
      Returns:
      the category of the instruction
      See Also:
      • CATEGORY_ALU
      • CATEGORY_JUMP
      • CATEGORY_BRANCH
      • CATEGORY_MEM
      • CATEGORY_OTHER
    • memoryRead

      public void memoryRead(int address, int length, int value, int wordAddress, int wordValue)
      Method that is called each time the MIPS simulator accesses the text segment. Before an instruction is executed by the simulator, the instruction is fetched from the program memory. This memory access is observed and the corresponding instruction is decoded and categorized by the tool. According to the category the counter values are increased and the display gets updated.
      Parameters:
      address - The address which was read from.
      length - The number of bytes read. Will always be 1 (single byte), Memory.BYTES_PER_HALFWORD, or Memory.BYTES_PER_WORD.
      value - The value which was read.
      wordAddress - The address of the word affected by the operation.
      wordValue - The full value of the word.
    • initializePreGUI

      protected void initializePreGUI()
      performs initialization tasks of the counters before the GUI is created.
      Overrides:
      initializePreGUI in class AbstractMarsTool
    • reset

      protected void reset()
      resets the counter values of the tool and updates the display.
      Overrides:
      reset in class AbstractMarsTool