|
|
@ -20,8 +20,8 @@ import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Disassembles the TAM code in the given file, and displays the |
|
|
|
* Disassembles the TAM code in the given file, and displays the instructions on |
|
|
|
* instructions on standard output. |
|
|
|
* standard output. |
|
|
|
* |
|
|
|
* |
|
|
|
* For example: |
|
|
|
* For example: |
|
|
|
* |
|
|
|
* |
|
|
@ -38,361 +38,361 @@ import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
public class Disassembler { |
|
|
|
public class Disassembler { |
|
|
|
|
|
|
|
|
|
|
|
static String objectName; |
|
|
|
static String objectName; |
|
|
|
|
|
|
|
|
|
|
|
static int CT; |
|
|
|
static int CT; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where |
|
|
|
* Writes the r-field of an instruction in the form "l<I>reg</I>r", where l and |
|
|
|
* l and r are the bracket characters to use. |
|
|
|
* r are the bracket characters to use. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param leftbracket the character to print before the register. |
|
|
|
* @param leftbracket the character to print before the register. |
|
|
|
* @param r the number of the register. |
|
|
|
* @param r the number of the register. |
|
|
|
* @param rightbracket the character to print after the register. |
|
|
|
* @param rightbracket the character to print after the register. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void writeR(char leftbracket, int r, char rightbracket) { |
|
|
|
private static void writeR(char leftbracket, int r, char rightbracket) { |
|
|
|
|
|
|
|
|
|
|
|
System.out.print(leftbracket); |
|
|
|
System.out.print(leftbracket); |
|
|
|
switch (r) { |
|
|
|
switch (r) { |
|
|
|
case Machine.CBr: |
|
|
|
case Machine.CBr: |
|
|
|
System.out.print("CB"); |
|
|
|
System.out.print("CB"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.CTr: |
|
|
|
case Machine.CTr: |
|
|
|
System.out.print("CT"); |
|
|
|
System.out.print("CT"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.PBr: |
|
|
|
case Machine.PBr: |
|
|
|
System.out.print("PB"); |
|
|
|
System.out.print("PB"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.PTr: |
|
|
|
case Machine.PTr: |
|
|
|
System.out.print("PT"); |
|
|
|
System.out.print("PT"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.SBr: |
|
|
|
case Machine.SBr: |
|
|
|
System.out.print("SB"); |
|
|
|
System.out.print("SB"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.STr: |
|
|
|
case Machine.STr: |
|
|
|
System.out.print("ST"); |
|
|
|
System.out.print("ST"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.HBr: |
|
|
|
case Machine.HBr: |
|
|
|
System.out.print("HB"); |
|
|
|
System.out.print("HB"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.HTr: |
|
|
|
case Machine.HTr: |
|
|
|
System.out.print("HT"); |
|
|
|
System.out.print("HT"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.LBr: |
|
|
|
case Machine.LBr: |
|
|
|
System.out.print("LB"); |
|
|
|
System.out.print("LB"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L1r: |
|
|
|
case Machine.L1r: |
|
|
|
System.out.print("L1"); |
|
|
|
System.out.print("L1"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L2r: |
|
|
|
case Machine.L2r: |
|
|
|
System.out.print("L2"); |
|
|
|
System.out.print("L2"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L3r: |
|
|
|
case Machine.L3r: |
|
|
|
System.out.print("L3"); |
|
|
|
System.out.print("L3"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L4r: |
|
|
|
case Machine.L4r: |
|
|
|
System.out.print("L4"); |
|
|
|
System.out.print("L4"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L5r: |
|
|
|
case Machine.L5r: |
|
|
|
System.out.print("L5"); |
|
|
|
System.out.print("L5"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.L6r: |
|
|
|
case Machine.L6r: |
|
|
|
System.out.print("L6"); |
|
|
|
System.out.print("L6"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.CPr: |
|
|
|
case Machine.CPr: |
|
|
|
System.out.print("CP"); |
|
|
|
System.out.print("CP"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
System.out.print(rightbracket); |
|
|
|
System.out.print(rightbracket); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes a void n-field of an instruction. |
|
|
|
* Writes a void n-field of an instruction. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void blankN() { |
|
|
|
private static void blankN() { |
|
|
|
System.out.print(" "); |
|
|
|
System.out.print(" "); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Writes the n-field of an instruction.
|
|
|
|
// Writes the n-field of an instruction.
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the n-field of an instruction in the form "(n)". |
|
|
|
* Writes the n-field of an instruction in the form "(n)". |
|
|
|
* |
|
|
|
* |
|
|
|
* @param n the integer to write. |
|
|
|
* @param n the integer to write. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void writeN(int n) { |
|
|
|
private static void writeN(int n) { |
|
|
|
System.out.print("(" + n + ") "); |
|
|
|
System.out.print("(" + n + ") "); |
|
|
|
if (n < 10) |
|
|
|
if (n < 10) |
|
|
|
System.out.print(" "); |
|
|
|
System.out.print(" "); |
|
|
|
else if (n < 100) |
|
|
|
else if (n < 100) |
|
|
|
System.out.print(" "); |
|
|
|
System.out.print(" "); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the d-field of an instruction. |
|
|
|
* Writes the d-field of an instruction. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param d the integer to write. |
|
|
|
* @param d the integer to write. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void writeD(int d) { |
|
|
|
private static void writeD(int d) { |
|
|
|
System.out.print(d); |
|
|
|
System.out.print(d); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the name of primitive routine with relative address d. |
|
|
|
* Writes the name of primitive routine with relative address d. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param d the displacment of the primitive routine. |
|
|
|
* @param d the displacment of the primitive routine. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void writePrimitive(int d) { |
|
|
|
private static void writePrimitive(int d) { |
|
|
|
switch (d) { |
|
|
|
switch (d) { |
|
|
|
case Machine.idDisplacement: |
|
|
|
case Machine.idDisplacement: |
|
|
|
System.out.print("id "); |
|
|
|
System.out.print("id "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.notDisplacement: |
|
|
|
case Machine.notDisplacement: |
|
|
|
System.out.print("not "); |
|
|
|
System.out.print("not "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.andDisplacement: |
|
|
|
case Machine.andDisplacement: |
|
|
|
System.out.print("and "); |
|
|
|
System.out.print("and "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.orDisplacement: |
|
|
|
case Machine.orDisplacement: |
|
|
|
System.out.print("or "); |
|
|
|
System.out.print("or "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.succDisplacement: |
|
|
|
case Machine.succDisplacement: |
|
|
|
System.out.print("succ "); |
|
|
|
System.out.print("succ "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.predDisplacement: |
|
|
|
case Machine.predDisplacement: |
|
|
|
System.out.print("pred "); |
|
|
|
System.out.print("pred "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.negDisplacement: |
|
|
|
case Machine.negDisplacement: |
|
|
|
System.out.print("neg "); |
|
|
|
System.out.print("neg "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.addDisplacement: |
|
|
|
case Machine.addDisplacement: |
|
|
|
System.out.print("add "); |
|
|
|
System.out.print("add "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.subDisplacement: |
|
|
|
case Machine.subDisplacement: |
|
|
|
System.out.print("sub "); |
|
|
|
System.out.print("sub "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.multDisplacement: |
|
|
|
case Machine.multDisplacement: |
|
|
|
System.out.print("mult "); |
|
|
|
System.out.print("mult "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.divDisplacement: |
|
|
|
case Machine.divDisplacement: |
|
|
|
System.out.print("div "); |
|
|
|
System.out.print("div "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.modDisplacement: |
|
|
|
case Machine.modDisplacement: |
|
|
|
System.out.print("mod "); |
|
|
|
System.out.print("mod "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.ltDisplacement: |
|
|
|
case Machine.ltDisplacement: |
|
|
|
System.out.print("lt "); |
|
|
|
System.out.print("lt "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.leDisplacement: |
|
|
|
case Machine.leDisplacement: |
|
|
|
System.out.print("le "); |
|
|
|
System.out.print("le "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.geDisplacement: |
|
|
|
case Machine.geDisplacement: |
|
|
|
System.out.print("ge "); |
|
|
|
System.out.print("ge "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.gtDisplacement: |
|
|
|
case Machine.gtDisplacement: |
|
|
|
System.out.print("gt "); |
|
|
|
System.out.print("gt "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.eqDisplacement: |
|
|
|
case Machine.eqDisplacement: |
|
|
|
System.out.print("eq "); |
|
|
|
System.out.print("eq "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.neDisplacement: |
|
|
|
case Machine.neDisplacement: |
|
|
|
System.out.print("ne "); |
|
|
|
System.out.print("ne "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.eolDisplacement: |
|
|
|
case Machine.eolDisplacement: |
|
|
|
System.out.print("eol "); |
|
|
|
System.out.print("eol "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.eofDisplacement: |
|
|
|
case Machine.eofDisplacement: |
|
|
|
System.out.print("eof "); |
|
|
|
System.out.print("eof "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.getDisplacement: |
|
|
|
case Machine.getDisplacement: |
|
|
|
System.out.print("get "); |
|
|
|
System.out.print("get "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.putDisplacement: |
|
|
|
case Machine.putDisplacement: |
|
|
|
System.out.print("put "); |
|
|
|
System.out.print("put "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.geteolDisplacement: |
|
|
|
case Machine.geteolDisplacement: |
|
|
|
System.out.print("geteol "); |
|
|
|
System.out.print("geteol "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.puteolDisplacement: |
|
|
|
case Machine.puteolDisplacement: |
|
|
|
System.out.print("puteol "); |
|
|
|
System.out.print("puteol "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.getintDisplacement: |
|
|
|
case Machine.getintDisplacement: |
|
|
|
System.out.print("getint "); |
|
|
|
System.out.print("getint "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.putintDisplacement: |
|
|
|
case Machine.putintDisplacement: |
|
|
|
System.out.print("putint "); |
|
|
|
System.out.print("putint "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.newDisplacement: |
|
|
|
case Machine.newDisplacement: |
|
|
|
System.out.print("new "); |
|
|
|
System.out.print("new "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Machine.disposeDisplacement: |
|
|
|
case Machine.disposeDisplacement: |
|
|
|
System.out.print("dispose "); |
|
|
|
System.out.print("dispose "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes the given instruction in assembly-code format. |
|
|
|
* Writes the given instruction in assembly-code format. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param instr the instruction to display. |
|
|
|
* @param instr the instruction to display. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void writeInstruction(Instruction instr) { |
|
|
|
private static void writeInstruction(Instruction instr) { |
|
|
|
|
|
|
|
|
|
|
|
switch (instr.op) { |
|
|
|
switch (instr.op) { |
|
|
|
case Machine.LOADop: |
|
|
|
case Machine.LOADop: |
|
|
|
System.out.print("LOAD "); |
|
|
|
System.out.print("LOAD "); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.LOADAop: |
|
|
|
case Machine.LOADAop: |
|
|
|
System.out.print("LOADA "); |
|
|
|
System.out.print("LOADA "); |
|
|
|
blankN(); |
|
|
|
blankN(); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.LOADIop: |
|
|
|
case Machine.LOADIop: |
|
|
|
System.out.print("LOADI "); |
|
|
|
System.out.print("LOADI "); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.LOADLop: |
|
|
|
case Machine.LOADLop: |
|
|
|
System.out.print("LOADL "); |
|
|
|
System.out.print("LOADL "); |
|
|
|
blankN(); |
|
|
|
blankN(); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.STOREop: |
|
|
|
case Machine.STOREop: |
|
|
|
System.out.print("STORE "); |
|
|
|
System.out.print("STORE "); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.STOREIop: |
|
|
|
case Machine.STOREIop: |
|
|
|
System.out.print("STOREI"); |
|
|
|
System.out.print("STOREI"); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.CALLop: |
|
|
|
case Machine.CALLop: |
|
|
|
System.out.print("CALL "); |
|
|
|
System.out.print("CALL "); |
|
|
|
if (instr.r == Machine.PBr) { |
|
|
|
if (instr.r == Machine.PBr) { |
|
|
|
blankN(); |
|
|
|
blankN(); |
|
|
|
writePrimitive(instr.d); |
|
|
|
writePrimitive(instr.d); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
writeR('(', instr.n, ')'); |
|
|
|
writeR('(', instr.n, ')'); |
|
|
|
System.out.print(" "); |
|
|
|
System.out.print(" "); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.CALLIop: |
|
|
|
case Machine.CALLIop: |
|
|
|
System.out.print("CALLI "); |
|
|
|
System.out.print("CALLI "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.RETURNop: |
|
|
|
case Machine.RETURNop: |
|
|
|
System.out.print("RETURN"); |
|
|
|
System.out.print("RETURN"); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.PUSHop: |
|
|
|
case Machine.PUSHop: |
|
|
|
System.out.print("PUSH "); |
|
|
|
System.out.print("PUSH "); |
|
|
|
blankN(); |
|
|
|
blankN(); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.POPop: |
|
|
|
case Machine.POPop: |
|
|
|
System.out.print("POP "); |
|
|
|
System.out.print("POP "); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.JUMPop: |
|
|
|
case Machine.JUMPop: |
|
|
|
System.out.print("JUMP "); |
|
|
|
System.out.print("JUMP "); |
|
|
|
blankN(); |
|
|
|
blankN(); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.JUMPIop: |
|
|
|
case Machine.JUMPIop: |
|
|
|
System.out.print("JUMPI "); |
|
|
|
System.out.print("JUMPI "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.JUMPIFop: |
|
|
|
case Machine.JUMPIFop: |
|
|
|
System.out.print("JUMPIF"); |
|
|
|
System.out.print("JUMPIF"); |
|
|
|
writeN(instr.n); |
|
|
|
writeN(instr.n); |
|
|
|
writeD(instr.d); |
|
|
|
writeD(instr.d); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
writeR('[', instr.r, ']'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case Machine.HALTop: |
|
|
|
case Machine.HALTop: |
|
|
|
System.out.print("HALT "); |
|
|
|
System.out.print("HALT "); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Writes all instructions of the program in code store. |
|
|
|
* Writes all instructions of the program in code store. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void disassembleProgram() { |
|
|
|
private static void disassembleProgram() { |
|
|
|
for (int addr = Machine.CB; addr < CT; addr++) { |
|
|
|
for (int addr = Machine.CB; addr < CT; addr++) { |
|
|
|
System.out.print(addr + ": "); |
|
|
|
System.out.print(addr + ": "); |
|
|
|
writeInstruction(Machine.code[addr]); |
|
|
|
writeInstruction(Machine.code[addr]); |
|
|
|
System.out.println(); |
|
|
|
System.out.println(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// LOADING
|
|
|
|
// LOADING
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Loads the TAM object program into code store from the named file. |
|
|
|
* Loads the TAM object program into code store from the named file. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param objectName the name of the file containing the program. |
|
|
|
* @param objectName the name of the file containing the program. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void loadObjectProgram(String objectName) { |
|
|
|
static void loadObjectProgram(String objectName) { |
|
|
|
|
|
|
|
|
|
|
|
FileInputStream objectFile = null; |
|
|
|
FileInputStream objectFile = null; |
|
|
|
DataInputStream objectStream = null; |
|
|
|
DataInputStream objectStream = null; |
|
|
|
|
|
|
|
|
|
|
|
int addr; |
|
|
|
int addr; |
|
|
|
boolean finished = false; |
|
|
|
boolean finished = false; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
objectFile = new FileInputStream(objectName); |
|
|
|
objectFile = new FileInputStream(objectName); |
|
|
|
objectStream = new DataInputStream(objectFile); |
|
|
|
objectStream = new DataInputStream(objectFile); |
|
|
|
|
|
|
|
|
|
|
|
addr = Machine.CB; |
|
|
|
addr = Machine.CB; |
|
|
|
while (!finished) { |
|
|
|
while (!finished) { |
|
|
|
Machine.code[addr] = Instruction.read(objectStream); |
|
|
|
Machine.code[addr] = Instruction.read(objectStream); |
|
|
|
if (Machine.code[addr] == null) |
|
|
|
if (Machine.code[addr] == null) |
|
|
|
finished = true; |
|
|
|
finished = true; |
|
|
|
else |
|
|
|
else |
|
|
|
addr = addr + 1; |
|
|
|
addr = addr + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
CT = addr; |
|
|
|
CT = addr; |
|
|
|
objectFile.close(); |
|
|
|
objectFile.close(); |
|
|
|
} catch (FileNotFoundException s) { |
|
|
|
} catch (FileNotFoundException s) { |
|
|
|
CT = Machine.CB; |
|
|
|
CT = Machine.CB; |
|
|
|
System.err.println("Error opening object file: " + s); |
|
|
|
System.err.println("Error opening object file: " + s); |
|
|
|
} catch (IOException s) { |
|
|
|
} catch (IOException s) { |
|
|
|
CT = Machine.CB; |
|
|
|
CT = Machine.CB; |
|
|
|
System.err.println("Error reading object file: " + s); |
|
|
|
System.err.println("Error reading object file: " + s); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DISASSEMBLE
|
|
|
|
// DISASSEMBLE
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********"); |
|
|
|
System.out.println("********** TAM Disassembler (Sun Version 2.1) **********"); |
|
|
|
|
|
|
|
|
|
|
|
if (args.length == 1) |
|
|
|
if (args.length == 1) |
|
|
|
objectName = args[0]; |
|
|
|
objectName = args[0]; |
|
|
|
else |
|
|
|
else |
|
|
|
objectName = "obj.tam"; |
|
|
|
objectName = "obj.tam"; |
|
|
|
|
|
|
|
|
|
|
|
loadObjectProgram(objectName); |
|
|
|
loadObjectProgram(objectName); |
|
|
|
disassembleProgram(); |
|
|
|
disassembleProgram(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|