fi.hu.cs.titokone
Class BinaryInterpreter

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

public class BinaryInterpreter
extends Interpreter

This class contains the information to translate a command in binary form to its symbolic string form. Naturally, if a command has been transformed from its symbolic form to binary, the transformation back will not restore used symbols as we cannot tell, even with the help of the symbol table, what symbol has been used where.


Field Summary
private  java.util.HashMap commands
          This hashmap contains the symbolic commands as strings, with Integer forms of their opcodes as keys.
static java.lang.String GARBLE
           
private  java.util.HashMap parameters
          This hashmap contains parameters for each command with Integer forms of their opcodes as keys.
 
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
BinaryInterpreter()
          This constructor sets up a binaryinterpreter and initializes the internal command information data structures.
 
Method Summary
 int binaryToInt(java.lang.String binaryValue, boolean signIncluded)
          This method converts String that contains a binary to int.
 java.lang.String binaryToString(int binaryCommand)
          This function transforms a binary-form command to its symbolic representation.
 java.lang.String getAddressFromBinary(int binaryCommand)
          If a given binary represents a valid command that has an address then this function returns it.
 java.lang.String getFirstRegisterFromBinary(int binaryCommand)
          If a command has a first register value then this function returns it.
 java.lang.String getMemoryModeFromBinary(int binaryCommand)
          Function returns possible memory address mode from a binary command given as a parameter.
 java.lang.String getOpCodeFromBinary(int binaryCommand)
          This command returns the operation code from a binary
 java.lang.String getSecondRegisterFromBinary(int binaryCommand)
          If a command has second register value, this function returns it "" or R0 to R7).
 java.lang.String intToBinary(long value, int bits)
          This method converts int values to binary-string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GARBLE

public static final java.lang.String GARBLE
See Also:
Constant Field Values

commands

private java.util.HashMap commands
This hashmap contains the symbolic commands as strings, with Integer forms of their opcodes as keys.


parameters

private java.util.HashMap parameters
This hashmap contains parameters for each command with Integer forms of their opcodes as keys.

Constructor Detail

BinaryInterpreter

public BinaryInterpreter()
This constructor sets up a binaryinterpreter and initializes the internal command information data structures.

Method Detail

binaryToString

public java.lang.String binaryToString(int binaryCommand)
This function transforms a binary-form command to its symbolic representation. Binary is interpreted in two parts, firstly the first 8 bits of the binary representation are extracted and if it is a valid opcode then check the needed bits if they make any sense. Like if the opcode is a NOP then all the bits can be 0, or anything else. Also check what to return. Like in a case of NOP there is no need to return other parameters. http://www.cs.helsinki.fi/u/ahakkine/Tito/koksi.kaskyt Check Compiler.java for more info on checking a binary.

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
The symbolic representation if it is valid enough. If the opcode is unknown, the memory address mode faulty or the register ids do not point to real registers, BinaryInterpreter.GARBLE is returned.

getOpCodeFromBinary

public java.lang.String getOpCodeFromBinary(int binaryCommand)
This command returns the operation code from a binary

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
Operation code in a String format.

getFirstRegisterFromBinary

public java.lang.String getFirstRegisterFromBinary(int binaryCommand)
If a command has a first register value then this function returns it. (NOP has none, thus it would return "") Normally value would be a value from R0 to R7

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
Possible register value in a String format.

getMemoryModeFromBinary

public java.lang.String getMemoryModeFromBinary(int binaryCommand)
Function returns possible memory address mode from a binary command given as a parameter. Four possible values (non excistent, and three legal values)

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
Memory address mode from binary command in a String format.

getSecondRegisterFromBinary

public java.lang.String getSecondRegisterFromBinary(int binaryCommand)
If a command has second register value, this function returns it "" or R0 to R7).

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
Possible other register from binary command in a String format.

getAddressFromBinary

public java.lang.String getAddressFromBinary(int binaryCommand)
If a given binary represents a valid command that has an address then this function returns it.

Parameters:
binaryCommand - The command's binary-form representation.
Returns:
Address part of the binary command in a String format.

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.