Class Inst

java.lang.Object
  extended by Asm
      extended by Inst

public class Inst
extends Asm

Inst class. Represents a generic instruction (ALU, memory, branch, jump, load immediate, system call).


Field Summary
protected  boolean limmFlag
          Flag indicating whether long immediate field is an immediate (true) or label (false)
protected  int limmImm
          Long immediate field as an immediate (int).
protected  java.lang.String limmLabel
          Long immediate field as a label (string).
protected  int opcode
          Opcode of the instruction.
protected  int ra
          Register identifier for the destination register (in the RA slot).
protected  int rb
          Register identifier for the first source register (in the RB slot).
protected  int rc
          Register identifier for the second source register (in the RC slot).
protected  int simm
          Short immediate field (int).
 
Fields inherited from class Asm
addr, lineNumber
 
Constructor Summary
Inst(int opcode, java.lang.String ra, java.lang.String rb, java.lang.String rc, java.lang.String simm, java.lang.String limm, int lineNumber)
          Instruction constructor.
 
Method Summary
 boolean getLIMMFlag()
          Gets flag indicating whether LIMM is an int or label -- ultimately LIMM needs to be converted to an int.
 int getLIMMImm()
          Gets LIMM as an immediate (int) for the instruction (note: LIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.
 java.lang.String getLIMMLabel()
          Gets LIMM as a label (string) for the instruction (note: LIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.
static java.lang.String getOp(int opcode)
          Gets string representation of the operation (e.g., "add") from opcode See the ISA description for a list of operations and their respective opcodes.
 int getOpcode()
          Returns the instruction's opcode.
static int getOpcode(java.lang.String op)
          Gets opcode from a string representation of the operation (e.g., "add") See the ISA description for a list of operations and their respective opcodes.
 int getRA()
          Gets RA identifier for the instruction (note: RA is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.
 int getRB()
          Gets RB identifier for the instruction (note: RB is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.
 int getRC()
          Gets RC identifier for the instruction (note: RC is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.
 int getSIMM()
          Gets SIMM immediate (int).
 boolean isALU()
          Checks if instruction is an ALU instruction
static boolean isALU(int opcode)
          Checks if opcode is an ALU opcode
 boolean isBranch()
          Checks if instruction is a branch instruction
static boolean isBranch(int opcode)
          Checks if opcode is a branch opcode
 boolean isExtended()
          Checks if instruction is an extended instruction
static boolean isExtended(int opcode)
          Is this an extended instruction?
 boolean isJump()
          Checks if instruction is a jump instruction
static boolean isJump(int opcode)
          Checks if opcode is a jump opcode
 boolean isLoadImm()
          Checks if instruction is a load immediate instruction
static boolean isLoadImm(int opcode)
          Checks if opcode is a load immediate opcode
 boolean isMem()
          Checks if instruction is a memory instruction
static boolean isMem(int opcode)
          Checks if opcode is a memory opcode
 boolean isSysCall()
          Checks if instruction is a system call instruction
static boolean isSysCall(int opcode)
          Checks if opcode is a system call opcode
 boolean isSysRetn()
          Checks if instruction is a system return instruction
static boolean isSysRetn(int opcode)
          Checks if opcode is a system return opcode
 void setLIMMImm(int limmImm)
          Sets the LIMM immediate Note: this has to be done for all instructions using labels in place of LIMM immediate
 void setSIMMImm(int simm)
          Sets the SIMM immediate Note: this may need to be done if supporting extended instructions (for short immediates that don't fit in 4 bits)
 
Methods inherited from class Asm
getAddr, getLineNumber, setAddr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

opcode

protected int opcode
Opcode of the instruction.


ra

protected int ra
Register identifier for the destination register (in the RA slot).


rb

protected int rb
Register identifier for the first source register (in the RB slot).


rc

protected int rc
Register identifier for the second source register (in the RC slot).


simm

protected int simm
Short immediate field (int).


limmFlag

protected boolean limmFlag
Flag indicating whether long immediate field is an immediate (true) or label (false)


limmImm

protected int limmImm
Long immediate field as an immediate (int).


limmLabel

protected java.lang.String limmLabel
Long immediate field as a label (string).

Constructor Detail

Inst

public Inst(int opcode,
            java.lang.String ra,
            java.lang.String rb,
            java.lang.String rc,
            java.lang.String simm,
            java.lang.String limm,
            int lineNumber)
Instruction constructor. Note: some of the parameters may not be relevant for some instructions (e.g., immediate in an ALU instruction). Takes arguments in the order of assembly language syntax and checks that they are proper arguments.

Parameters:
opcode - numeric opcode for the instruction.
ra - RA register identifier.
rb - RB register identifier.
rc - RC register identifier.
simm - short immediate field (either an immediate or a label).
limm - long immediate field (either an immediate or a label).
lineNumber - line number of instruction.
Method Detail

getOpcode

public int getOpcode()
Returns the instruction's opcode.

Returns:
instruction's opcode

getOpcode

public static int getOpcode(java.lang.String op)
Gets opcode from a string representation of the operation (e.g., "add") See the ISA description for a list of operations and their respective opcodes.

Parameters:
op - string representation of the operation
Returns:
opcode

getOp

public static java.lang.String getOp(int opcode)
Gets string representation of the operation (e.g., "add") from opcode See the ISA description for a list of operations and their respective opcodes.

Parameters:
opcode - opcode of instruction
Returns:
string representation of the operation

getRA

public int getRA()
Gets RA identifier for the instruction (note: RA is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
RA identifier

getRB

public int getRB()
Gets RB identifier for the instruction (note: RB is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
RB identifier

getRC

public int getRC()
Gets RC identifier for the instruction (note: RC is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
RC identifier

getSIMM

public int getSIMM()
Gets SIMM immediate (int). (note: SIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
SIMM immediate(int)

setSIMMImm

public void setSIMMImm(int simm)
Sets the SIMM immediate Note: this may need to be done if supporting extended instructions (for short immediates that don't fit in 4 bits)

Parameters:
simm - short immediate

getLIMMFlag

public boolean getLIMMFlag()
Gets flag indicating whether LIMM is an int or label -- ultimately LIMM needs to be converted to an int. (note: LIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
flag indicating whether LIMM is represented as immediate (true) of label (false)

getLIMMImm

public int getLIMMImm()
Gets LIMM as an immediate (int) for the instruction (note: LIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
LIMM immediate

getLIMMLabel

public java.lang.String getLIMMLabel()
Gets LIMM as a label (string) for the instruction (note: LIMM is only applicable for certain instructions) See the ISA description for a list of operations and their respective operands.

Returns:
LIMM label

setLIMMImm

public void setLIMMImm(int limmImm)
Sets the LIMM immediate Note: this has to be done for all instructions using labels in place of LIMM immediate

Parameters:
limmImm - LIMM as an immediate (int)

isALU

public static boolean isALU(int opcode)
Checks if opcode is an ALU opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is an ALU opcode

isALU

public boolean isALU()
Checks if instruction is an ALU instruction

Returns:
boolean indicating whether instruction is an ALU instruction

isLoadImm

public static boolean isLoadImm(int opcode)
Checks if opcode is a load immediate opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a load immediate opcode

isLoadImm

public boolean isLoadImm()
Checks if instruction is a load immediate instruction

Returns:
boolean indicating whether instruction is a load immediate instruction

isBranch

public static boolean isBranch(int opcode)
Checks if opcode is a branch opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a branch opcode

isBranch

public boolean isBranch()
Checks if instruction is a branch instruction

Returns:
boolean indicating whether instruction is a branch instruction

isMem

public static boolean isMem(int opcode)
Checks if opcode is a memory opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a memory opcode

isMem

public boolean isMem()
Checks if instruction is a memory instruction

Returns:
boolean indicating whether instruction is a memory instruction

isJump

public static boolean isJump(int opcode)
Checks if opcode is a jump opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a jump opcode

isJump

public boolean isJump()
Checks if instruction is a jump instruction

Returns:
boolean indicating whether instruction is a jump instruction

isSysCall

public static boolean isSysCall(int opcode)
Checks if opcode is a system call opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a system call opcode

isSysCall

public boolean isSysCall()
Checks if instruction is a system call instruction

Returns:
boolean indicating whether instruction is a system call instruction

isSysRetn

public static boolean isSysRetn(int opcode)
Checks if opcode is a system return opcode

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is a system return opcode

isSysRetn

public boolean isSysRetn()
Checks if instruction is a system return instruction

Returns:
boolean indicating whether instruction is a system return instruction

isExtended

public static boolean isExtended(int opcode)
Is this an extended instruction?

Parameters:
opcode - opcode to check
Returns:
boolean indicating whether opcode is an extended instruction opcode

isExtended

public boolean isExtended()
Checks if instruction is an extended instruction

Returns:
boolean indicating whether instruction is an extended instruction