Package mars.mips.hardware
Class RegisterFile
java.lang.Object
mars.mips.hardware.RegisterFile
Represents the collection of MIPS registers.
- Version:
- June 2003
- Author:
- Jason Bumgarner, Jason Shrewsbury
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
static int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
For returning the program counter's initial (reset) value.static int
For getting the number representation of the register.static int
For returning the program counters value.static Register
Returns Register object for program counter.static Register[]
For returning the set of registers.static Register
getUserRegister(String regName)
Get register object corresponding to given name.static int
getValue(int num)
Returns the value of the register whose number is num.static void
Method to increment the Program counter in the general case (not a jump or branch).static void
initializeProgramCounter(boolean startAtMain)
Will initialize the Program Counter to either the default reset value, or the address associated with source program global label "main", if it exists as a text segment label and the global setting is set.static void
initializeProgramCounter(int value)
For initializing the Program Counter.static void
Method to reinitialize the values of the registers.static int
setProgramCounter(int value)
For setting the Program Counter.static void
Display the register values for debugging.static int
updateRegister(int num, int val)
This method updates the register value whose number is num.static void
updateRegister(String reg, int val)
Sets the value of the register given to the value given.
-
Field Details
-
GLOBAL_POINTER_REGISTER
public static final int GLOBAL_POINTER_REGISTER- See Also:
- Constant Field Values
-
STACK_POINTER_REGISTER
public static final int STACK_POINTER_REGISTER- See Also:
- Constant Field Values
-
-
Constructor Details
-
RegisterFile
public RegisterFile()
-
-
Method Details
-
showRegisters
public static void showRegisters()Display the register values for debugging. -
updateRegister
public static int updateRegister(int num, int val)This method updates the register value whose number is num. Also handles the lo and hi registers- Parameters:
num
- Register to set the value of.val
- The desired value for the register.
-
updateRegister
Sets the value of the register given to the value given.- Parameters:
reg
- Name of register to set the value of.val
- The desired value for the register.
-
getValue
public static int getValue(int num)Returns the value of the register whose number is num.- Parameters:
num
- The register number.- Returns:
- The value of the given register.
-
getNumber
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 or -1 if no match.
-
getRegisters
For returning the set of registers.- Returns:
- The set of registers.
-
getUserRegister
Get register object corresponding to given name. If no match, return null.- Parameters:
regName
- The register name, either in $0 or $zero format.- Returns:
- The register object,or null if not found.
-
initializeProgramCounter
public static void initializeProgramCounter(int value)For initializing the Program Counter. Do not use this to implement jumps and branches, as it will NOT record a backstep entry with the restore value. If you need backstepping capability, use setProgramCounter instead.- Parameters:
value
- The value to set the Program Counter to.
-
initializeProgramCounter
public static void initializeProgramCounter(boolean startAtMain)Will initialize the Program Counter to either the default reset value, or the address associated with source program global label "main", if it exists as a text segment label and the global setting is set.- Parameters:
startAtMain
- If true, will set program counter to address of statement labeled 'main' (or other defined start label) if defined. If not defined, or if parameter false, will set program counter to default reset value.
-
setProgramCounter
public static int setProgramCounter(int value)For setting the Program Counter. Note that ordinary PC update should be done using incrementPC() method. Use this only when processing jumps and branches.- Parameters:
value
- The value to set the Program Counter to.- Returns:
- previous PC value
-
getProgramCounter
public static int getProgramCounter()For returning the program counters value.- Returns:
- The program counters value as an int.
-
getProgramCounterRegister
Returns Register object for program counter. Use with caution.- Returns:
- program counter's Register object.
-
getInitialProgramCounter
public static int getInitialProgramCounter()For returning the program counter's initial (reset) value.- Returns:
- The program counter's initial value
-
resetRegisters
public static void resetRegisters()Method to reinitialize the values of the registers. NOTE: Should not be called from command-mode MARS because this this method uses global settings from the registry. Command-mode must operate using only the command switches, not registry settings. It can be called from tools running stand-alone, and this is done inAbstractMarsToolAndApplication
. -
incrementPC
public static void incrementPC()Method to increment the Program counter in the general case (not a jump or branch). -
addRegistersObserver
Each individual register is a separate object and Observable. This handy method will add the given Observer to each one. Currently does not apply to Program Counter. -
deleteRegistersObserver
Each individual register is a separate object and Observable. This handy method will delete the given Observer from each one. Currently does not apply to Program Counter.
-