0% found this document useful (0 votes)
81 views5 pages

Two-Pass Assembler Pass-II Implementation

The document describes Pass 2 of a two-pass assembler for a pseudo-machine. It contains code to read symbol and literal tables, map operation codes to addresses or symbols, and write the resulting machine code to a new file. The code uses hashmaps to store and look up symbol names and addresses from the input tables during the second pass over the intermediate file.

Uploaded by

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

Topics covered

  • Compiler Design,
  • Project Structure,
  • Programming Concepts,
  • Memory Management,
  • Debugging,
  • Refactoring,
  • Assembler,
  • Data Structures,
  • FileWriter,
  • Version Control
0% found this document useful (0 votes)
81 views5 pages

Two-Pass Assembler Pass-II Implementation

The document describes Pass 2 of a two-pass assembler for a pseudo-machine. It contains code to read symbol and literal tables, map operation codes to addresses or symbols, and write the resulting machine code to a new file. The code uses hashmaps to store and look up symbol names and addresses from the input tables during the second pass over the intermediate file.

Uploaded by

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

Topics covered

  • Compiler Design,
  • Project Structure,
  • Programming Concepts,
  • Memory Management,
  • Debugging,
  • Refactoring,
  • Assembler,
  • Data Structures,
  • FileWriter,
  • Version Control

Assignment 1 Pass2

Design suitable Data structures and implement Pass-II of a two-pass assembler for
pseudo-machine

[Link]
import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class Pass2 {

public static void main(String[] Args) throws IOException{

BufferedReader b1 = new BufferedReader(new FileReader("D:\\SITS_NARHE\\LP-


1\\Programs\\Expt-2\\[Link]"));

BufferedReader b2 = new BufferedReader(new FileReader("D:\\SITS_NARHE\\LP-1\\


Programs\\Expt-2\\[Link]"));

BufferedReader b3 = new BufferedReader(new FileReader("D:\\SITS_NARHE\\LP-1\\


Programs\\Expt-2\\[Link]"));

FileWriter f1 = new FileWriter("D:\\SITS_NARHE\\LP-1\\Programs\\Expt-2\\[Link]");

HashMap<Integer, String> symSymbol = new HashMap<Integer, String>();

HashMap<Integer, String> litSymbol = new HashMap<Integer, String>();

HashMap<Integer, String> litAddr = new HashMap<Integer, String>();

String s;

int symtabPointer=1,littabPointer=1,offset;

while((s=[Link]())!=null){

String word[]=[Link]("\t\t\t");

[Link](symtabPointer++,word[1]);

while((s=[Link]())!=null){

String word[]=[Link]("\t\t");

[Link](littabPointer,word[0]);
[Link](littabPointer++,word[1]);

while((s=[Link]())!=null){

if([Link](1,6).compareToIgnoreCase("IS,00")==0){

[Link]("+ 00 0 000\n");

else if([Link](1,3).compareToIgnoreCase("IS")==0){

[Link]("+ "+[Link](4,6)+" ");

if([Link](9)==')'){

[Link]([Link](8)+" ");

offset=3;

else{

[Link]("0 ");

offset=0;

if([Link](8+offset)=='S')

[Link]([Link]([Link]([Link](10+offset,[Link]()-1)))+"\n");

else

[Link]([Link]([Link]([Link](10+offset,[Link]()-1)))+"\n");

else if([Link](1,6).compareToIgnoreCase("DL,01")==0){

String s1=[Link](10,[Link]()-1),s2="";

for(int i=0;i<[Link]();i++)

s2+="0";

s2+=s1;

[Link]("+ 00 0 "+s2+"\n");

else{

[Link]("\n");
}

[Link]();

[Link]();

[Link]();

[Link]();

[Link]("Pass2 file has been created");

BufferedReader op = new BufferedReader(new FileReader("D:\\SITS_NARHE\\LP-1\\


Programs\\Expt-2\\[Link]"));

while((s=[Link]())!=null){

[Link](s);

Input File
[Link]
(AD,01)(C,200)
(IS,04)(1)(L,1)
(IS,05)(1)(S,1)
(IS,04)(1)(S,1)
(IS,04)(3)(S,3)
(IS,01)(3)(L,2)
(IS,07)(6)(S,4)
(DL,01)(C,5)
(DL,01)(C,1)
(IS,02)(1)(L,3)
(IS,07)(1)(S,5)
(IS,00)
(AD,03)(S,2)+2
(IS,03)(3)(S,3)
(AD,03)(S,6)+1
(DL,02)(C,1)
(DL,02)(C,1)
(AD,02)
(DL,01)(C,1)

[Link]
5 206
1 207
1 213

[Link]
A 211 1
LOOP 202 1
B 212 1
NEXT 208 1
BACK 202 1
LAST 210 1

Output :

Pass2 file has been created

+ 04 1 206
+ 05 1 211
+ 04 1 211
+ 04 3 212
+ 01 3 207
+ 07 6 208
+ 00 0 005
+ 00 0 001
+ 02 1 213
+ 07 1 202
+ 00 0 000

+ 03 3 212

+ 00 0 001

You might also like