I want to design a simple assembler for IBM360 assembly language.so i'm implementing symbol table first. i'm storing my symbols/labels in a separate file so as to compare it while generating the symbol table.the problem im facing is ,the incorrect location counter(LC) value due to unwanted comparisions.I'm able to detect the symbols but with the wrong LC value. can anyone guide me in modifying my code?
Here is my program :
import java.io.*;
import java.lang.*;
class SymbolTable
{
public static void main(String args[]) throws Exception
{
FileReader fr = new FileReader("program.asm");
BufferedReader br = new BufferedReader(fr);
String s,l;
String code[]=new String[100];
String label[]=new String[100];
int N=0,i,LOC=0,n=0,j;
System.out.println("Assembly lang program :\n--------------------------");
while((s = br.readLine()) != null)
{
code[N++]=s;
System.out.println(s);
}
fr.close();
FileReader labels = new FileReader("label.txt");
BufferedReader buff = new BufferedReader(labels);
while((s = buff.readLine()) != null)
{
label[n++]=s;
}
labels.close();
System.out.println("\n\n SYMBOL TABLE :\n-------------------------------------------\nLABEL\tLC\tLENGTH\tRELATIVE/ABSOLUTE\n-------------------------------------------");
for(i=0;i<N;i++)
{
for(j=0;j<n;j++)
{
char codearr[]=new char[15];
codearr=code[i].toCharArray();
if(code[i].startsWith("USING"))
{
break;
}
else if(code[i].startsWith(label[j]))
{
System.out.println(label[j]+"\t"+LOC+"\t4\tR");
if(i==0)
{}
else
LOC=LOC+4;
break;
}
else if(codearr[1]=='R') // for register addressing mode
LOC=LOC+2;
else
LOC=LOC+4;
}
}
}
}
program.asm:
JOHN START
USING *,15
L 1,FIVE
A 1,FOUR
ST 1,TEMP
FOUR DC F '4'
FIVE DC F '5'
TEMP DS 1F
END
label.txt
JOHN
FOUR
FIVE
TEMP
output :
G:\programs>javac SymbolTable.java
G:\programs>java SymbolTable
Assembly lang program :
--------------------------
JOHN START
USING *,15
LR 1,FIVE
A 1,FOUR
ST 1,TEMP
FOUR DC F '4'
FIVE DC F '5'
TEMP DS 1F
END
SYMBOL TABLE :
-------------------------------------------
LABEL LC LENGTH RELATIVE/ABSOLUTE
-------------------------------------------
JOHN 0 4 R
FOUR 44 4 R
FIVE 56 4 R
TEMP 72 4 R
j
. – PM 77-1else if
. Does it make sense or have I missed something here? – PM 77-1