Views:
These are the System Programming and Compiler Construction (SPCC) programs for practical exam of TE COMPS (2011-12). Refer it and modify according to the need.
(You can download all the SPCC programs from SkyDrive. Click here to download...)
1. TWO PASS ASSEMBLER
/* Note: Please create a Sp.txt file at the same place where you are saving this .java file. Copy the these lines in the text file
JOHN START 0
USING *,15
L 1,FIVE
A 1,FOUR
ST 1,TEMP
FOUR DC F'4'
FIVE DC F'5'
TEMP DS 1F
END and only then compile and run the program.
*/
import java.io.*;
class Assembler
{
FileInputStream fin= new FileInputStream("Sp.txt");
DataInputStream in= new DataInputStream(fin);
String s[]=new String[20]; int n,i;
String mot[][]=new String[20][20]; int top;
String pot[][]=new String[20][20]; int top1;
String st[][]=new String[20][20]; int top2;
String bt[][]=new String[20][2];
String lt[][]=new String[20][20]; int top3;
String pass1[][]=new String[20][20]; int top4;
String pass2[][]=new String[20][20];
int j,lc,reg,f1,f2,f3;
boolean flag;
Assembler()throws IOException
{
i=top=top1=top2=top3=top4=-1;
String temp=in.readLine();
while(temp!=null)
{
s[++i]=temp;
temp=in.readLine();
}
n=i;
for(j=0;j<=15;j++)
{
bt[j][0]="N";
bt[j][1]="-";
}
}
void initialize()
{
String psedo_char[]={ "START" , "USING" , "DROP" , "EQU" , "END" , "DS" , "DC" };
String mcop[]={ "A" , "L" , "ST" , "MVC" };
String dtype[]= { "DS" , "DC" };
compute(psedo_char,mcop,dtype);
display();
}
void compute(String psedo_char[],String mcop[],String dtype[])
{
int p1,p2,p3,p4;
String s1;
char c1;
f1=f2=f3=-1;
boolean f6=false;
lc=0;
flag=true;
for(i=0;i<=n;i++)
{
f1=s[i].indexOf("START");
f2=s[i].indexOf("USING");
f3=s[i].indexOf("L ");
findlc();