Aim: To Implement First Pass of Two Pass Assembler For IBM 360/370 Objective: Develop A Program To Implement First Pass
Aim: To Implement First Pass of Two Pass Assembler For IBM 360/370 Objective: Develop A Program To Implement First Pass
Aim: To Implement First Pass of Two Pass Assembler For IBM 360/370 Objective: Develop A Program To Implement First Pass
Aim: To implement first pass of two pass assembler for IBM 360/370
Objective: Develop a program to implement first pass
Pass 1: Database
1. Source program
2. Location counter (LC) which stores location of each instruction
3. MOT this table indicates the symbolic mnemonic for each instruction and its length.
4. POT this table indicates the symbolic mnemonic and action taken for each pseudo-op
in pass 1.
5. Symbol Table which stores each label along with value.
6. Literal Table (LT) which stores each literal and its corresponding address.
7. A copy of input will be used by pass 2.
Flowchart for Pass 1:
Programs:
Program in JAVA:
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;
}
}
}
}
PG1 start
using * 15
L, 4,N1
A, 4,N2
ST 4,N
N1 DC F'1'
N2 DC F'2'
N DS 1F
END
Output: