|
Here is my method to get the symbols from the code and assign them to the symbol table:
int currAddr = 16;
public void getSymbols() {
for(int i=0; i<cmdArray.size(); i++) {
String temp = cmdArray.get(i);
if(temp.contains("(")) {
String temp2 = temp.substring(1);
String temp3 = temp2.replaceAll("\\)", "");
String addr = String.format("%16s", Integer.toBinaryString(i)).replace(" ", "0");
symTbl.addEntry(temp3, addr);
cmdArray.remove(i);
}
}
for(int i=0; i<cmdArray.size(); i++) {
String temp = cmdArray.get(i);
if(temp.contains("@")) {
String temp2 = temp.substring(1);
if(!(isInteger(temp2)) && !(symTbl.contains(temp2))) {
String addr = String.format("%16s", Integer.toBinaryString(currAddr)).replace(" ", "0");
symTbl.addEntry(temp2, addr);
currAddr++;
}
}
}
}
|