-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
875b007
commit 699c74c
Showing
10 changed files
with
394 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package Assembler; | ||
|
||
import OperandPkg.Literal; | ||
import OperandPkg.OperandUtility; | ||
import SymbolPkg.*; | ||
|
||
import java.io.*; | ||
import java.util.LinkedList; | ||
|
||
// NAME : Quazi Irfan | ||
// CLASS : CSc 354 | ||
// ASSIGNMENT : 2 | ||
// DUE DATE : 10/5/16 | ||
// INSTRUCTOR : Dr. Hamer | ||
// DESCRIPTION : Assignment 2 : Expressions | ||
|
||
/** | ||
* Assembler.Main is the Entry point Assignment 2 : Expressions | ||
* | ||
* Thic class checks if two arguments were supplied, or it prompts the user to enter them. | ||
* If <2 arguments were supplied then it terminates the execution. | ||
* The user has to reload the program to try again. | ||
* | ||
* After setting the input file, the program calls static methods to, | ||
* 1. Populate the Symbol Table | ||
* 2. Evaluate and print all valid expressions | ||
* 3. Print the literals | ||
* | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) throws IOException{ | ||
SymbolTable symbolTable = new SymbolTable(); | ||
LinkedList<Literal> literalLnkdLst = new LinkedList<>(); | ||
|
||
// Set input files | ||
String symbolFile, operandFile; | ||
if(args.length < 2){ | ||
System.out.println("Missing command like argument."); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
System.out.print("Enter Symbol File : "); | ||
symbolFile = reader.readLine(); | ||
System.out.print("Enter Expressions File : "); | ||
operandFile = reader.readLine(); | ||
} else { | ||
symbolFile = args[0]; | ||
operandFile = args[1]; | ||
} | ||
|
||
// Check the existence of both symbol and operand file | ||
File f = new File(symbolFile); | ||
if(!f.exists()) { | ||
System.out.println(symbolFile + " not found. Please rerun the program to try again."); | ||
return; | ||
} | ||
|
||
f = new File(operandFile); | ||
if(!f.exists()) { | ||
System.out.println(operandFile + " not found. Please rerun the program to try again."); | ||
return; | ||
} | ||
|
||
// Populate Symbol Table | ||
SymbolUtility.populateSymbolTable(symbolTable, symbolFile); | ||
System.out.println("*** SYMBOL TABLE ***\nSymbol\t Value\t rflag\t iflag\t mflag\t"); | ||
symbolTable.view(); | ||
|
||
// Evaluate and print Expressions | ||
System.out.println("\n*** EXPRESSIONS ***\nExpresion\t Value\t Relocatable n i x"); | ||
OperandUtility.evaluateOperand(symbolTable, literalLnkdLst, operandFile); | ||
|
||
// Print contents of the literal table | ||
System.out.println("\n*** LITERAL TABLE ***\nName\t\t Value\t\t Size\t Address"); | ||
for(Object o : literalLnkdLst){ | ||
System.out.println(o); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package Assembler; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
/** | ||
* This Utility class is meant for temporary code segments that doesn't fit in other classes. | ||
* | ||
*/ | ||
|
||
public class Utility { | ||
/** | ||
* This method prompts the user the press Enter to continue. | ||
*/ | ||
public static void enterToContinue(){ | ||
System.out.print(" *** Press Enter to continue..."); | ||
try{ | ||
BufferedReader tempHalt = new BufferedReader(new InputStreamReader(System.in)); | ||
tempHalt.readLine(); | ||
} catch (IOException e){ | ||
System.out.println(e); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
package OperandPkg; | ||
|
||
/** | ||
* Each literal is an entry to the Literal Table | ||
* | ||
* Literals are addressed 1,2...n. The starting address is a static number, | ||
* and upon each successful entry to the literal table the static int is increased. | ||
* | ||
* Other attributes of literal are public. | ||
*/ | ||
public class Literal { | ||
public static int staticAddress = 1; | ||
|
||
String name, value; | ||
int length, address; | ||
|
||
/** | ||
* Helper method that returns formatted attributes of a Literal | ||
*/ | ||
public String toString() { | ||
return name + " " + value + " " + length + " " + address; | ||
String output = String.format("%1$-12s %2$-16s %3$-7d %4$d", name, value, length, address); | ||
|
||
return output; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
package OperandPkg; | ||
|
||
/** | ||
* Each Operand is a processed non-literal Expression | ||
*/ | ||
public class Operand { | ||
public String expression; | ||
public int value; | ||
public boolean relocability, nbit, ibit, xbit; | ||
|
||
/* | ||
* This method returns a formatted operand attribute | ||
*/ | ||
public String toString() { | ||
return expression + " " + | ||
value + " " + | ||
(relocability ? "Relative":"Absolute") + " " + | ||
(nbit? "1":"0") + " " + | ||
(ibit? "1":"0") + " " + | ||
(xbit? "1":"0"); | ||
String output = String.format("%1$-16s %2$-7d %3$-11s %4$s %5$s %6$s", | ||
expression, | ||
value, | ||
(relocability ? "Relative":"Absolute"), | ||
(nbit? "1":"0"), | ||
(ibit? "1":"0"), | ||
(xbit? "1":"0")); | ||
|
||
return output; | ||
} | ||
} |
Oops, something went wrong.