Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## dioscuri.module.cpu
Class Util

    java.lang.Object
      dioscuri.module.cpu.Util

    public class Util

extends java.lang.Object

Author:
  Bram Lohman, Bart Kiers

Field Summary
`protected static boolean` | `cf`
`protected static int` | `lowerByteCarry`

Method Summary
`protected static byte[]` | `addRegRegDisp(byte[] reg1, byte[] reg2, byte[] displacement)` Adds two registers and the memory reference displacement. Does not check carry or overflow flags.
`protected static byte[]` | `addWords(byte[] word1, byte[] word2, int carryBit)` Adds two words (16-bit) including a possible carry bit. Takes care of possible carry from LSB to MSB.
`protected static byte[]` | `booleansToBytes(boolean[] booleans)` Converts a boolean[] into a byte[] Each boolean value is converted into a hexadecimal (0 or 1) value and placed in a byte[].
`protected static boolean[]` | `bytesToBooleans(byte[] bytes)` Converts a byte[] into a boolean[] Each bit is converted into a boolean value and placed in a boolean[].
`protected static boolean` | `checkParityOfByte(byte data)` Check the parity of a given byte and given size in bits.
`protected static java.lang.String` | `convertByteToString(byte b)`
`protected static byte` | `convertStringToByte(java.lang.String strValue)` Converts a given string into a byte of one integer
`protected static byte[]` | `convertStringToWord(java.lang.String strValue)` Converts a given string into a word of bytes
`protected static java.lang.String` | `convertWordToString(byte[] word)`
`static int` | `getExponent(double val)`
`static int` | `getExponent(float val)`
`static double` | `scalb(double d, int i)`
`static float` | `scalb(float f, int i)`
`protected static byte` | `signExtend(byte inputByte)` Determines the sign of the input byte and returns the complementary (sign-extended) byte
`protected static byte[]` | `subtractWords(byte[] word1, byte[] word2, int borrowBit)` Subtracts two words (16-bit) including a possible borrow bit. Takes care of possible borrow from LSB to MSB.
`protected static boolean` | `test_AF_ADD(byte input, byte result)` Test the auxiliary flag (AF) for addition with possible carry. AF is set when carry occurs to higher nibble.
`protected static boolean` | `test_AF_ShiftLeft(byte input, int shifts)` Test the auxiliary flag (AF) for shift operations with byte. AF is set when carry occurs.
`protected static boolean` | `test_AF_SUB(byte input, byte result)` Test the auxiliary flag (AF) for subtraction with possible borrow. AF is set when borrow occurs from higher nibble.
`protected static boolean` | `test_CF_ADD(byte[] input1, byte[] input2, int carry)` Test the carry flag for addition operations with words. CF is set when unsigned overflow occurs.
`protected static boolean` | `test_CF_ADD(byte input1, byte input2, int carry)` Test the carry flag for addition operations with bytes. CF is set when unsigned overflow occurs.
`protected static boolean` | `test_CF_SUB(byte[] input1, byte[] input2, int carry)` Test the carry flag for subtraction operations with words. CF is set when unsigned overflow occurs.
`protected static boolean` | `test_CF_SUB(byte input1, byte input2, int carry)` Test the carry flag for subtraction operations with bytes. CF is set when unsigned overflow occurs.
`protected static boolean` | `test_OF_ADD(byte[] input1, byte[] input2, byte[] result, int carry)` Test the overflow flag for addition operations with words. OF is set when 2's complement signed overflow occur.
`protected static boolean` | `test_OF_ADD(byte input1, byte input2, byte result, int carry)` Test the overflow flag for addition operations with bytes. OF is set when 2's complement signed overflow occur.
`protected static boolean` | `test_OF_SUB(byte[] input1, byte[] input2, byte[] result, int carry)` Test the overflow flag for subtraction operations with words. OF is set when 2's complement signed overflow occurs.
`protected static boolean` | `test_OF_SUB(byte input1, byte input2, byte result, int carry)` Test the overflow flag for subtraction operations with bytes. OF is set when 2's complement signed overflow occurs.

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

Field Detail

### cf

    protected static boolean cf

### lowerByteCarry

    protected static int lowerByteCarry

Method Detail

### checkParityOfByte

    protected static boolean checkParityOfByte(byte data)

  Check the parity of a given byte and given size in bits.

  Parameters:
    `data` -
  Returns:
    -

### addWords

    protected static byte[] addWords(byte[] word1,
                                     byte[] word2,
                                     int carryBit)

  Adds two words (16-bit) including a possible carry bit.
  Takes care of possible carry from LSB to MSB. Not beyond MSB. Does not care about signed/unsigned as this doesn't effect the actual result in hex.

  Parameters:
    `word1` - first word
    `word2` - second word
    `carryBit` -
  Returns:
    sum of both words including possible carry between LSB and MSB

### subtractWords

    protected static byte[] subtractWords(byte[] word1,
                                          byte[] word2,
                                          int borrowBit)

  Subtracts two words (16-bit) including a possible borrow bit.
  Takes care of possible borrow from LSB to MSB. Not beyond MSB. Does not care about signed/unsigned as this doesn't effect the actual result in hex. Operation: word1 - (word2 + borrow)

  Parameters:
    `word1` - first word
    `word2` - second word
    `borrowBit` -
  Returns:
    subtraction of both words plus borrow including possible borrow between LSB and MSB

### addRegRegDisp

    protected static byte[] addRegRegDisp(byte[] reg1,
                                          byte[] reg2,
                                          byte[] displacement)

  Adds two registers and the memory reference displacement.
  Does not check carry or overflow flags.

  Parameters:
    `reg1` - first register to be added
    `reg2` - second register to be added
    `displacement` -
  Returns:
    sum of both registers and memory displacement

### test_AF_ADD

    protected static boolean test_AF_ADD(byte input,
                                         byte result)

  Test the auxiliary flag (AF) for addition with possible carry.
  AF is set when carry occurs to higher nibble.

  Parameters:
    `input` -
    `result` -
  Returns:
    true if carry occurs, false otherwise

### test_AF_SUB

    protected static boolean test_AF_SUB(byte input,
                                         byte result)

  Test the auxiliary flag (AF) for subtraction with possible borrow.
  AF is set when borrow occurs from higher nibble.

  Parameters:
    `input` -
    `result` -
  Returns:
    true if borrow occurs, false otherwise

### test_AF_ShiftLeft

    protected static boolean test_AF_ShiftLeft(byte input,
                                               int shifts)

  Test the auxiliary flag (AF) for shift operations with byte.
  AF is set when carry occurs. This happens when last shift causes a carry out of lowest nibble

  Parameters:
    `input` -
    `shifts` -
  Returns:
    true if carry/borrow occurs, false otherwise

### test_CF_ADD

    protected static boolean test_CF_ADD(byte input1,
                                         byte input2,
                                         int carry)

  Test the carry flag for addition operations with bytes.
  CF is set when unsigned overflow occurs. This happens when we cross over from 255 to 0 while adding or cross over from 0 to 255 while subtracting. The operation is (input1 + carry) + input2

  Parameters:
    `input1` -
    `input2` -
    `carry` -
  Returns:
    true if carry occurs, false otherwise

### test_CF_ADD

    protected static boolean test_CF_ADD(byte[] input1,
                                         byte[] input2,
                                         int carry)

  Test the carry flag for addition operations with words.
  CF is set when unsigned overflow occurs. This happens when we cross over from 65535 (0xFFFF) to 0 while adding or cross over from 0 to 65535 (0xFFFF) while subtracting. The operation is (input1 + carry) + input2

  Parameters:
    `input1` -
    `input2` -
    `carry` -
  Returns:
    true if carry occurs, false otherwise

### test_CF_SUB

    protected static boolean test_CF_SUB(byte input1,
                                         byte input2,
                                         int carry)

  Test the carry flag for subtraction operations with bytes.
  CF is set when unsigned overflow occurs. This happens when we cross over from 255 to 0 while adding or cross over from 0 to 255 while subtracting. The operation is input1 - (input2 + carry)

  Parameters:
    `input1` - unsigned input1 of operation
    `input2` - unsigned input2 of operation
    `carry` - possible carry bit
  Returns:
    true if borrow occurs, false otherwise

### test_CF_SUB

    protected static boolean test_CF_SUB(byte[] input1,
                                         byte[] input2,
                                         int carry)

  Test the carry flag for subtraction operations with words.
  CF is set when unsigned overflow occurs. This happens when we cross over from 255 to 0 while adding or cross over from 0 to 255 while subtracting. The operation is input1 - (input2 + carry)

  Parameters:
    `input1` -
    `input2` -
    `carry` -
  Returns:
    true if borrow occurs, false otherwise

### test_OF_ADD

    protected static boolean test_OF_ADD(byte input1,
                                         byte input2,
                                         byte result,
                                         int carry)

  Test the overflow flag for addition operations with bytes.
  OF is set when 2's complement signed overflow occur. This happens when we cross over from 127 to -128 while adding or cross over from -128 to 127 while subtracting.

  Parameters:
    `input1` -
    `input2` -
    `result` -
    `carry` -
  Returns:
    true if overflow occurs, false otherwise

### test_OF_ADD

    protected static boolean test_OF_ADD(byte[] input1,
                                         byte[] input2,
                                         byte[] result,
                                         int carry)

  Test the overflow flag for addition operations with words.
  OF is set when 2's complement signed overflow occur. This happens when we cross over from 32767 (0x7FFF) to -32768 (0x8000) while adding or cross over from -32768 to 32767 while subtracting.

  Parameters:
    `input1` -
    `result` -
    `input2` -
    `carry` -
  Returns:
    true if overflow occurs, false otherwise

### test_OF_SUB

    protected static boolean test_OF_SUB(byte input1,
                                         byte input2,
                                         byte result,
                                         int carry)

  Test the overflow flag for subtraction operations with bytes.
  OF is set when 2's complement signed overflow occurs. This happens when we cross over from 127 to -128 while adding or cross over from -128 to 127 while subtracting.

  Parameters:
    `input1` -
    `input2` -
    `carry` -
    `result` -
  Returns:
    true if overflow occurs, false otherwise

### test_OF_SUB

    protected static boolean test_OF_SUB(byte[] input1,
                                         byte[] input2,
                                         byte[] result,
                                         int carry)

  Test the overflow flag for subtraction operations with words.
  OF is set when 2's complement signed overflow occurs. This happens when we cross over from 32767 (0x7FFF) to -32768 (0x8000) while adding or cross over from -32768 to 32767 while subtracting.

  Parameters:
    `input1` -
    `input2` -
    `result` -
    `carry` -
  Returns:
    true if overflow occurs, false otherwise

### signExtend

    protected static byte signExtend(byte inputByte)

  Determines the sign of the input byte and returns the complementary (sign-extended) byte

  Parameters:
    `inputByte` - Byte whose sign determines value of sign-extension
  Returns:
    Byte of value 0x00 if no sign, 0xFF if signed

### booleansToBytes

    protected static byte[] booleansToBytes(boolean[] booleans)

  Converts a boolean[] into a byte[] Each boolean value is converted into a hexadecimal (0 or 1) value and placed in a byte[]. Note: boolean[] must be of multiple of 8 booleans.

  Parameters:
    `booleans` -
  Returns:
    byte[] containing the converted booleans

### bytesToBooleans

    protected static boolean[] bytesToBooleans(byte[] bytes)

  Converts a byte[] into a boolean[] Each bit is converted into a boolean value and placed in a boolean[].

  Parameters:
    `bytes` -
  Returns:
    boolean[] containing the converted bytes

### convertByteToString

    protected static java.lang.String convertByteToString(byte b)

  Parameters:
    `b` -
  Returns:
    -

### convertWordToString

    protected static java.lang.String convertWordToString(byte[] word)

  Parameters:
    `word` -
  Returns:
    -

### convertStringToByte

    protected static byte convertStringToByte(java.lang.String strValue)

  Converts a given string into a byte of one integer

  Parameters:
    `strValue` -
  Returns:
    int as byte

### convertStringToWord

    protected static byte[] convertStringToWord(java.lang.String strValue)

  Converts a given string into a word of bytes

  Parameters:
    `strValue` -
  Returns:
    byte[] as word

### getExponent

    public static int getExponent(double val)

  Parameters:
    `val` -
  Returns:
    -

### getExponent

    public static int getExponent(float val)

  Parameters:
    `val` -
  Returns:
    -

### scalb

    public static double scalb(double d,
                               int i)

  Parameters:
    `d` -
    `i` -
  Returns:
    -

### scalb

    public static float scalb(float f,
                              int i)

  Parameters:
    `f` -
    `i` -
  Returns:
    -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD