fi.hu.cs.titokone
Class SymbolicInterpreter

java.lang.Object
  extended byfi.hu.cs.titokone.Interpreter
      extended byfi.hu.cs.titokone.SymbolicInterpreter

public class SymbolicInterpreter
extends Interpreter

This class contains the bulk data needed to translate commands to opcodes etc. The main purpose for this class is to provide methods to convert symbolic commands to binary form.


Field Summary
private  java.util.HashMap addressModes
          This hashtable contains integer values for given addressingmodes.
private  java.util.HashMap opcodes
          This hashtable contains the opcode values keyed to the symbolic commands.
private  java.util.HashMap registers
          This hashtable
 
Fields inherited from class fi.hu.cs.titokone.Interpreter
ADDR, ADDR_LESS_FETCHES, addressFieldLength, addressingData, addressModeLength, commandData, FULL, FULL_LESS_FETCHES, NONE, opcodeLength, REG, REG_DEVICE, registerData, registerFieldLength, SP_ONLY, SP_REG, SVC
 
Constructor Summary
SymbolicInterpreter()
          This constructor sets up a SymbolicInterpreter instance.
 
Method Summary
 int binaryToInt(java.lang.String binaryValue, boolean signIncluded)
          This method converts String that contains a binary to int.
private  void dataSetup()
          This method sets up the HashTables.
 int getAddressingMode(java.lang.String identifier)
          This method transforms an addressing mode (=, @ or nothing) to a number identifying it.
 int getOpcode(java.lang.String command)
          This method checks if a command is a valid opCode.
 int getRegisterId(java.lang.String registerName)
          This method returns the binary form of a given register as an integer.
 java.lang.String intToBinary(long value, int bits)
          This method converts int values to binary-string.
 int stringToBinary(java.lang.String opcode, java.lang.String firstRegister, java.lang.String addressingMode, java.lang.String address, java.lang.String otherRegister)
          This method coverts a complete command in a symbolic form to a binary form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

opcodes

private java.util.HashMap opcodes
This hashtable contains the opcode values keyed to the symbolic commands.


addressModes

private java.util.HashMap addressModes
This hashtable contains integer values for given addressingmodes.


registers

private java.util.HashMap registers
This hashtable

Constructor Detail

SymbolicInterpreter

public SymbolicInterpreter()
This constructor sets up a SymbolicInterpreter instance. It calls the private method dataSetup() to set up its data structures.

Method Detail

dataSetup

private void dataSetup()
This method sets up the HashTables.


getOpcode

public int getOpcode(java.lang.String command)
This method checks if a command is a valid opCode.

Parameters:
command - String form of a possible opCode.

getAddressingMode

public int getAddressingMode(java.lang.String identifier)
This method transforms an addressing mode (=, @ or nothing) to a number identifying it.

Parameters:
identifier - String form of an addressing mode.
Returns:
Int value telling how many times memory must be accessed.

getRegisterId

public int getRegisterId(java.lang.String registerName)
This method returns the binary form of a given register as an integer.

Parameters:
registerName - String form of a register (R0-R7, SP or FP).
Returns:
Int value of a given register.

stringToBinary

public int stringToBinary(java.lang.String opcode,
                          java.lang.String firstRegister,
                          java.lang.String addressingMode,
                          java.lang.String address,
                          java.lang.String otherRegister)
This method coverts a complete command in a symbolic form to a binary form. caller must split up the original command and give the parts as parameters

Parameters:
opcode - String form of an operation code. (STORE)
firstRegister - String form of a first register. (R0-R7, SP or FP)
addressingMode - = or @ or an empty string that representes the memory addressing mode.
address - String form of an address, must be a valid int.
otherRegister - String form of an other register. (R0-R7, SP or FP)
Returns:
Int format of a symbolic opCode. (etc 00000010 00101000 00000000 01100100 as int)

intToBinary

public java.lang.String intToBinary(long value,
                                    int bits)
This method converts int values to binary-string. intToBinary(1,2) --> "01"

Parameters:
value - Int value to be converted.
bits - How many bits can be used .
Returns:
String representation of a said Int.

binaryToInt

public int binaryToInt(java.lang.String binaryValue,
                       boolean signIncluded)
This method converts String that contains a binary to int. binaryToInt("01") --> 1

Parameters:
binaryValue - String representing the binary, if other than {0,1} then null.
signIncluded - Boolean value telling whether 11 is -1 or 3 i.e. will the leading one be interpreted as sign-bit.
Returns:
Int value of a Binary.