## mars.mips.hardware
Class Coprocessor0

    java.lang.Object
      mars.mips.hardware.Coprocessor0

    public class Coprocessor0

extends Object

Represents Coprocessor 0. We will use only its interrupt/exception registers.

Author:
  Pete Sanderson

Field Summary
`static int` `CAUSE`
`static int` `DEFAULT_STATUS_VALUE`
`static int` `EPC`
`static int` `EXCEPTION_LEVEL`
`static int` `STATUS`
`static int` `VADDR` Coprocessor register names

Constructor Summary
`Coprocessor0()`

Method Summary
`static void` `addRegistersObserver(Observer observer)` Each individual register is a separate object and Observable.
`static void` `deleteRegistersObserver(Observer observer)` Each individual register is a separate object and Observable.
`static int` `getNumber(String n)` For getting the number representation of the register.
`static Register` `getRegister(String rname)` Get register object corresponding to given name.
`static int` `getRegisterPosition(Register r)` Coprocessor0 implements only selected registers, so the register number (8, 12, 13, 14) does not correspond to its position in the list of registers (0, 1, 2, 3).
`static Register[]` `getRegisters()` For returning the set of registers.
`static int` `getValue(int num)` Returns the value of the register who's number is num.
`static void` `resetRegisters()` Method to reinitialize the values of the registers.
`static void` `showRegisters()` Method for displaying the register values for debugging.
`static int` `updateRegister(int num, int val)` This method updates the register value who's number is num.
`static int` `updateRegister(String n, int val)` Sets the value of the register given to the value given.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### VADDR

    public static final int VADDR

  Coprocessor register names

  See Also:
    Constant Field Values

### STATUS

    public static final int STATUS

See Also:
  Constant Field Values

### CAUSE

    public static final int CAUSE

See Also:
  Constant Field Values

### EPC

    public static final int EPC

See Also:
  Constant Field Values

### EXCEPTION_LEVEL

    public static final int EXCEPTION_LEVEL

See Also:
  Constant Field Values

### DEFAULT_STATUS_VALUE

    public static final int DEFAULT_STATUS_VALUE

See Also:
  Constant Field Values

Constructor Detail

### Coprocessor0

    public Coprocessor0()

Method Detail

### showRegisters

    public static void showRegisters()

  Method for displaying the register values for debugging.

### updateRegister

    public static int updateRegister(String n,
                                     int val)

  Sets the value of the register given to the value given.

  Parameters:
    `n` - name of register to set the value of ($n, where n is reg number).
    `val` - The desired value for the register.
  Returns:
    old value in register prior to update

### updateRegister

    public static int updateRegister(int num,
                                     int val)

  This method updates the register value who's number is num.

  Parameters:
    `num` - Number of register to set the value of.
    `val` - The desired value for the register.
  Returns:
    old value in register prior to update

### getValue

    public static int getValue(int num)

  Returns the value of the register who's number is num.

  Parameters:
    `num` - The register number.
  Returns:
    The value of the given register. 0 for non-implemented registers

### getNumber

    public static int getNumber(String n)

  For getting the number representation of the register.

  Parameters:
    `n` - The string formatted register name to look for.
  Returns:
    The number of the register represented by the string. -1 if no match.

### getRegisters

    public static Register[] getRegisters()

  For returning the set of registers.

  Returns:
    The set of registers.

### getRegisterPosition

    public static int getRegisterPosition(Register r)

  Coprocessor0 implements only selected registers, so the register number (8, 12, 13, 14) does not correspond to its position in the list of registers (0, 1, 2, 3).

  Parameters:
    `r` - A coprocessor0 Register
  Returns:
    the list position of given register, -1 if not found.

### getRegister

    public static Register getRegister(String rname)

  Get register object corresponding to given name. If no match, return null.

  Parameters:
    `rname` - The register name, in $0 format.
  Returns:
    The register object,or null if not found.

### resetRegisters

    public static void resetRegisters()

  Method to reinitialize the values of the registers.

### addRegistersObserver

    public static void addRegistersObserver(Observer observer)

  Each individual register is a separate object and Observable. This handy method will add the given Observer to each one.

### deleteRegistersObserver

    public static void deleteRegistersObserver(Observer observer)

  Each individual register is a separate object and Observable. This handy method will delete the given Observer from each one.