Aim: To Implement First Pass of Two Pass Assembler For IBM 360/370 Objective: Develop A Program To Implement First Pass

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Exp_4

Aim: To implement first pass of two pass assembler for IBM 360/370
Objective: Develop a program to implement first pass

• To generate Symbol table


• To generate intermediate code after pass 1
Theory:
An assembler performs the following functions
1. Generate instructions
a. Evaluate the mnemonic in operator flied to produce its machine code.
b. Evaluate subfields find value of each symbol, process literals and assign address.
2. Process pseudo ops.
Pass 1: Purpose – To define symbols &literals
1. Determine length of machine instruction (MOTGET)
2. Keep track of location counter (LC)
3. Remember values of symbols until pass 2 (STSTO)
4. Process some pseudo ops. EQU
5. Remember literals (LITSTO)

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;
}
}
}
}

Program in Assembly Language:

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:

You might also like