asm
Class AsmIns

java.lang.Object
  |
  +--asm.AsmIns

public class AsmIns
extends java.lang.Object

Represents a single assembly instruction. In writing this, I've come to realize that the MIPS instruction set is not so regular after all...


Field Summary
(package private) static java.util.Map funcMap
          Maps mnemonic -> integer (func field)
(package private) static java.util.Map funcValMap
          Maps integer -> instruction mnemonic.
(package private)  int m_ins
           
(package private)  boolean m_isJump
           
(package private)  java.lang.String m_label
           
(package private)  java.lang.String m_labelRef
           
(package private)  int m_line
           
(package private)  int m_num
           
(package private) static java.util.Map opMap
          Maps mnemonic -> integer (opcode)
(package private) static java.util.Map opValMap
          Maps integer -> instruction mnemonic
(package private) static java.util.Map regMap
          Maps mnemonic -> integer (register number)
(package private) static java.util.Map regValMap
          Maps integer -> register name
(package private) static java.util.Map typeMap
          Maps opcode mnemonic (string) -> encoding type.
 
Constructor Summary
AsmIns(int line, java.lang.String labelRef)
          Create a new instruction
 
Method Summary
 void addRefTo(java.util.Map refMap)
          If this instruction makes a reference to a label, its index is entered into the reference map.
static java.lang.String decodeIns(int ins)
          Decode this instruction.
 void enc(java.lang.String op)
           
 void encBType(java.lang.String op, java.lang.String rs, int imm)
          Encode a one register branch instruction, eg: BGEZ
 void encIType(java.lang.String op, java.lang.String rt, java.lang.String rs, int imm)
          Encode as an Itype instruction: two register branches and immediat arithmetic instructions, and loads/stores
 void encJRType(java.lang.String op, java.lang.String reg)
          Encode as a JRtype instruction.
 void encJType(java.lang.String op, int imm)
          Encode as a Jtype instruction.
 void encRType(java.lang.String op, java.lang.String rd, java.lang.String rs, java.lang.String rt)
          Encode as an Rtype instruction.
(package private) static void loadDecodeMap(java.util.Map map, java.lang.String fileName)
          DecodeMap must contains bindings Integer->String
(package private) static void loadMap(java.util.Map map, java.lang.String fileName)
           
 void setNum(int num)
           
 java.lang.String toString()
           
(package private) static int translateFunc(java.lang.String op)
           
(package private) static int translateOp(java.lang.String op)
           
(package private) static int translateReg(java.lang.String reg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_line

int m_line

m_ins

int m_ins

m_num

int m_num

m_labelRef

java.lang.String m_labelRef

m_label

java.lang.String m_label

m_isJump

boolean m_isJump

regMap

static java.util.Map regMap
Maps mnemonic -> integer (register number)


opMap

static java.util.Map opMap
Maps mnemonic -> integer (opcode)


funcMap

static java.util.Map funcMap
Maps mnemonic -> integer (func field)


regValMap

static java.util.Map regValMap
Maps integer -> register name


opValMap

static java.util.Map opValMap
Maps integer -> instruction mnemonic


funcValMap

static java.util.Map funcValMap
Maps integer -> instruction mnemonic.


typeMap

static java.util.Map typeMap
Maps opcode mnemonic (string) -> encoding type. 0 = r-type, 1 = i-type, 2 = j-type, 3 = jr-type, 4 = simple

Constructor Detail

AsmIns

public AsmIns(int line,
              java.lang.String labelRef)
Create a new instruction

Method Detail

loadMap

static void loadMap(java.util.Map map,
                    java.lang.String fileName)
             throws java.io.IOException
java.io.IOException

loadDecodeMap

static void loadDecodeMap(java.util.Map map,
                          java.lang.String fileName)
                   throws java.io.IOException
DecodeMap must contains bindings Integer->String

java.io.IOException

translateOp

static int translateOp(java.lang.String op)

translateReg

static int translateReg(java.lang.String reg)

translateFunc

static int translateFunc(java.lang.String op)

decodeIns

public static java.lang.String decodeIns(int ins)
Decode this instruction.


setNum

public void setNum(int num)

addRefTo

public void addRefTo(java.util.Map refMap)
If this instruction makes a reference to a label, its index is entered into the reference map.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

encRType

public void encRType(java.lang.String op,
                     java.lang.String rd,
                     java.lang.String rs,
                     java.lang.String rt)
Encode as an Rtype instruction.


encIType

public void encIType(java.lang.String op,
                     java.lang.String rt,
                     java.lang.String rs,
                     int imm)
Encode as an Itype instruction: two register branches and immediat arithmetic instructions, and loads/stores


encBType

public void encBType(java.lang.String op,
                     java.lang.String rs,
                     int imm)
Encode a one register branch instruction, eg: BGEZ


encJType

public void encJType(java.lang.String op,
                     int imm)
Encode as a Jtype instruction.


encJRType

public void encJRType(java.lang.String op,
                      java.lang.String reg)
Encode as a JRtype instruction.


enc

public void enc(java.lang.String op)