0% found this document useful (0 votes)
24 views1 page

Pass 1

The document is a Java program that implements the first pass of an assembler, processing assembly language instructions and generating a symbol table and intermediate code. It initializes a two-dimensional array with assembly instructions, tracks the location counter, and writes the symbol table and intermediate code to separate files. The program concludes by indicating that the first pass is complete and the necessary files have been generated.

Uploaded by

tsxbeast23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Pass 1

The document is a Java program that implements the first pass of an assembler, processing assembly language instructions and generating a symbol table and intermediate code. It initializes a two-dimensional array with assembly instructions, tracks the location counter, and writes the symbol table and intermediate code to separate files. The program concludes by indicating that the first pass is complete and the necessary files have been generated.

Uploaded by

tsxbeast23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package assembler;

import java.io.*;

public class Pass1 {


public static void main(String[] args) throws IOException {
String[][] a = {
{"", "START", "101", ""},
{"", "MOVER", "BREG", "ONE"},
{"AGAIN", "MULT", "BREG", "TERM"},
{"", "MOVER", "CREG", "TERM"},
{"", "ADD", "CREG", "N"},
{"", "MOVEM", "CREG", "TERM"},
{"N", "DS", "2", ""},
{"RESULT", "DS", "2", ""},
{"ONE", "DC", "1", ""},
{"TERM", "DS", "1", ""},
{"", "END", "", ""}
};

int lc = Integer.parseInt(a[0][2]);

// Symbol table
String[][] st = new String[10][2];
int symCnt = 0;

BufferedWriter symtab = new BufferedWriter(new FileWriter("symtab.txt"));


BufferedWriter inter = new BufferedWriter(new
FileWriter("intermediate.txt"));

for (int i = 1; i < a.length; i++) {


if (!a[i][0].equals("")) {
st[symCnt][0] = a[i][0];
st[symCnt][1] = Integer.toString(lc);
symtab.write(a[i][0] + "\t" + lc + "\n");
symCnt++;
}

inter.write(lc + "\t" + a[i][1] + "\t" + a[i][2] + "\t" + a[i][3] + "\


n");

if (a[i][1].equals("DS")) {
lc += Integer.parseInt(a[i][2]);
} else {
lc++;
}
}

symtab.close();
inter.close();

System.out.println("Pass-I complete. Symbol Table and Intermediate Code


generated.");
}
}

You might also like