SlideShare a Scribd company logo
1 of 7
Download to read offline
System Programming
Walchand Institute of Technology
Aim:
Design & implementation of
Theory:
Two pass translation
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols
in the program are entered into the symbol table. The second pass synthesizes the
target form using the address information found in the symbol table. In effect, the
first pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
shown in figure. This representation consists of two main components
structures, e.g. the symbol table, and a processed form of the source program. The
latter component is called intermediate code.
Figure: Overview of two pass assembly
Tasks performed by the passes of a two pass assembler are as follows:
• Pass I:
1. Separate the symbol, mnemonic, opcode and operand.
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
HANDOUT#06
Design & implementation of pass 1 of two pass assembler
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols
in the program are entered into the symbol table. The second pass synthesizes the
target form using the address information found in the symbol table. In effect, the
first pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
shown in figure. This representation consists of two main components
structures, e.g. the symbol table, and a processed form of the source program. The
called intermediate code.
Figure: Overview of two pass assembly
Tasks performed by the passes of a two pass assembler are as follows:
Separate the symbol, mnemonic, opcode and operand.
Sunita M. Dol, CSE Dept
Page 1
Two pass translation of an assembly language program can handle forward
references easily. LC processing is performed in the first pass and symbols defined
in the program are entered into the symbol table. The second pass synthesizes the
target form using the address information found in the symbol table. In effect, the
first pass performs synthesis of the target program. The first pass constructs an
intermediate representation of the source program for use by the second pass as
shown in figure. This representation consists of two main components—data
structures, e.g. the symbol table, and a processed form of the source program. The
Tasks performed by the passes of a two pass assembler are as follows:
Separate the symbol, mnemonic, opcode and operand.
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 2
2. Build Symbol Table.
3. Perform LC Processing.
4. Construct Intermediate Representation.
• Pass II:
1. Process IR to synthesize the target program.
Pass I performs analysis of the source program and the synthesis of the
intermediate representation while Pass II processes the intermediate representation
to synthesize the target program.
Pass I uses the following data structures:
OPTAB : A table of machine opcodes and related information
SYMTAB : Symbol table
LITTAB : A table of literals used in the program.
• OPTAB contains the fields mnemonic opcode, class and mnemonic info.
The class indicates whether the opcode corresponds to an IS (Imperative
statement), DL(Declaration statement) or AD (Assembler directives). If an
imperative statement then the mnemonic info field contains the pair
(mnemonic opcode, instruction length) else it contains the id of a routine to
handle the declaration or directive statement.
• SYTAB entry contains the fields address and length.
• LITTAB entry contains the fields literal and address.
Processing of an assembly statement:
• Begins with the processing of label field.
• If label fields contains a symbol, the symbol and the value in LC is
copied into a new entry of SYMTAB.
• For OPTAB entry, the class field of entry is examined to determine
whether the mnemonics belongs to the class of imperative, declaration or
assembler directive statements.
• In case of imperative statement, the length the machine instructions is
simply added to LC and length is also entered in the SYMTAB.
• For declaration or assembler directives statements, the routine is
mentioned in the mnemonic info field is called to perform appropriate
processing of the statement.
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 3
• The pass I use the LITTAB (Literal Table) to collect all literals used in a
program. Awareness of different literal pools is maintained using the
auxiliary table POOLTAB. This table contains the literal number of the
starting literal of each literal pool. At any stage, the current literal pool is
the last pool in LITTAB. On encountering an LTORG statement or END
statement, literals in the current pool are allocated addresses starting with
the current value in LC and LC is appropriately incremented.
Algorithm for Pass I
1. location_counter := 0
pooltable_ptr := 1
POOLTAB[1] := 1
litertable_ptr := 1
2. While next statement is not end statement
a. If label is present then
this_label := symbol in label field
Enter (this_label, location_counter) in SYMTAB
b. If LTROG statement then
i. Process literals LITTAB[POOLTAL[pooltable_ptr]]…
LITTAB[literaltable_ptr -1] to allocate memory and put the
address in the address field. Update location_counter
accordingly.
ii. Pooltable_ptr := pooltable_ptr + 1
iii. POOLTAB[pooltable_ptr] := literaltable_ptr
c. If START or ORIGIN statement then
location_counter := value specified in the operand field
d. If an EQU statement then
i. this_address := value of < address specification
ii. Correct symbol table entry
This_label (this_label, this_address)
e. If a declaration statement then
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 4
i. code := code of the declaration statement
ii. size := size of memory area required by DS or DC
iii. location_counter := location_counter + size
iv. Generate IC (DL, code)
f. If an imperative statement then
i. code := machine opcode from OPTAB
ii. location_counter := location_counter + instruction length from
OPTAB
iii. If operand is literal then
this_literal := literal in operand field
LITTAB [literaltable_ptr] := this_literal
Literaltable_ptr := literaltable_ptr + 1
Else (i.e. operand is a symbol)
this_entry := SYMTAB entry number of operands
Generate IC (IS, code) (S, this_entry)
3. Processing of end statement
i. Perform step(2)
ii. Generate intermediate code IC (AD, 02)
iii. Go to Pass II.
System Programming
Walchand Institute of Technology
Figure: Example to generate intermediate representation using Pass I of two pass
Input:
START 200
MOVER
MOVEM
LOOP MOVER
MOVER
ADD
BC
LTORG
='5'
='1'
NEXT SUB
BC
Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur
Figure: Example to generate intermediate representation using Pass I of two pass
assembler
START 200
MOVER AREG, ='5'
MOVEM AREG, A
MOVER AREG, A
MOVER CREG, B
CREG, ='1'
ANY, NEXT
LTORG
AREG, ='1'
LT, BACK
Sunita M. Dol, CSE Dept
Page 5
Figure: Example to generate intermediate representation using Pass I of two pass
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 6
LASTSTOP
ORIGIN LOOP+2
MULT CREG, B
ORIGIN LAST+1
A DS 1
BACK EQU LOOP
B DS 2
END
='1'
Output:
Symbol Table
0 A 211 1
1 LOOP 202 1
2 B 212 2
3 NEXT 208 1
4 BACK 202 1
5 LAST 210 1
6 =’1’ 215 1
Literal Table
0 =’5’ 206 1
1 =’1’ 207 1
2 =’1’ 214 1
Intermediate Representation
0 (AD, 01) (C, 200)
200 (IS, 04) (1) (L, 00)
201 (IS, 05) (1) (S, 00)
202 (IS, 04) (1) (S, 00)
203 (IS, 04) (3) (S, 02)
204 (IS, 01) (3) (L, 01)
205 (IS, 07) (6) (S, 03)
System Programming Sunita M. Dol, CSE Dept
Walchand Institute of Technology, Solapur Page 7
206 (AD, 05)
(L, 00)
(L, 01)
208 (IS, 02) (1) (L, 02)
209 (IS, 07) (1) (S, 04)
210 (IS, 00)
210 (AD, 03) (S, 01) + (C, 2)
204 (IS, 03) (3) (S, 02)
205 (AD, 03) (S, 05) + (C, 1)
211 (DL, 02) (C, 1)
212 (AD, 04) (S, 01)
212 (DL, 02) (C, 2)
214 (AD, 02)
(L, 02)
215
Conclusion:
Location counter processing is performed in the pass-I and symbols defined
in the program are entered into the symbol table.
Pass-I performs the analysis of source program.
Pass I:
Separate the symbol, mnemonic, opcode and operand.
Build Symbol Table.
Perform LC Processing.
Construct Intermediate Representation.
Thus the pass-I of two pass assembler is implemented in C-language.

More Related Content

What's hot (20)

Handout#02
Handout#02Handout#02
Handout#02
 
Handout#11
Handout#11Handout#11
Handout#11
 
Handout#09
Handout#09Handout#09
Handout#09
 
Assignment4
Assignment4Assignment4
Assignment4
 
Handout#12
Handout#12Handout#12
Handout#12
 
Assignment5
Assignment5Assignment5
Assignment5
 
Handout#01
Handout#01Handout#01
Handout#01
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
C language
C languageC language
C language
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
C language
C languageC language
C language
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
C notes
C notesC notes
C notes
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
 

Similar to Handout#06

Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System ProgrammingRadhika Talaviya
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03desta_gebre
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop AssemblerTuhin_Das
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlB.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlRai University
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlRai University
 
basic computer programming and micro programmed control
basic computer programming and micro programmed controlbasic computer programming and micro programmed control
basic computer programming and micro programmed controlRai University
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlMca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlRai University
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Compiler gate question key
Compiler gate question keyCompiler gate question key
Compiler gate question keyArthyR3
 
loaders-and-linkers.pdfhhhhhccftyghgfggy
loaders-and-linkers.pdfhhhhhccftyghgfggyloaders-and-linkers.pdfhhhhhccftyghgfggy
loaders-and-linkers.pdfhhhhhccftyghgfggyrahulyadav957181
 
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...IJERA Editor
 
The process of programming
 The process of programming The process of programming
The process of programmingKopi Maheswaran
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdfSemsemSameer1
 

Similar to Handout#06 (20)

assembler-ppt.pdf
assembler-ppt.pdfassembler-ppt.pdf
assembler-ppt.pdf
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
 
Assembler
AssemblerAssembler
Assembler
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop Assembler
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlB.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
 
basic computer programming and micro programmed control
basic computer programming and micro programmed controlbasic computer programming and micro programmed control
basic computer programming and micro programmed control
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlMca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed control
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
SPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptxSPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptx
 
Compiler gate question key
Compiler gate question keyCompiler gate question key
Compiler gate question key
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
loaders-and-linkers.pdfhhhhhccftyghgfggy
loaders-and-linkers.pdfhhhhhccftyghgfggyloaders-and-linkers.pdfhhhhhccftyghgfggy
loaders-and-linkers.pdfhhhhhccftyghgfggy
 
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...
A Novel Efficient VLSI Architecture for IEEE 754 Floating point multiplier us...
 
The process of programming
 The process of programming The process of programming
The process of programming
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
 

More from Sunita Milind Dol (17)

9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment10
Assignment10Assignment10
Assignment10
 
Assignment9
Assignment9Assignment9
Assignment9
 
Assignment8
Assignment8Assignment8
Assignment8
 
Assignment7
Assignment7Assignment7
Assignment7
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment3
Assignment3Assignment3
Assignment3
 
Assignment2
Assignment2Assignment2
Assignment2
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 

Handout#06

  • 1. System Programming Walchand Institute of Technology Aim: Design & implementation of Theory: Two pass translation Two pass translation of an assembly language program can handle forward references easily. LC processing is performed in the first pass and symbols in the program are entered into the symbol table. The second pass synthesizes the target form using the address information found in the symbol table. In effect, the first pass performs synthesis of the target program. The first pass constructs an intermediate representation of the source program for use by the second pass as shown in figure. This representation consists of two main components structures, e.g. the symbol table, and a processed form of the source program. The latter component is called intermediate code. Figure: Overview of two pass assembly Tasks performed by the passes of a two pass assembler are as follows: • Pass I: 1. Separate the symbol, mnemonic, opcode and operand. Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur HANDOUT#06 Design & implementation of pass 1 of two pass assembler Two pass translation of an assembly language program can handle forward references easily. LC processing is performed in the first pass and symbols in the program are entered into the symbol table. The second pass synthesizes the target form using the address information found in the symbol table. In effect, the first pass performs synthesis of the target program. The first pass constructs an intermediate representation of the source program for use by the second pass as shown in figure. This representation consists of two main components structures, e.g. the symbol table, and a processed form of the source program. The called intermediate code. Figure: Overview of two pass assembly Tasks performed by the passes of a two pass assembler are as follows: Separate the symbol, mnemonic, opcode and operand. Sunita M. Dol, CSE Dept Page 1 Two pass translation of an assembly language program can handle forward references easily. LC processing is performed in the first pass and symbols defined in the program are entered into the symbol table. The second pass synthesizes the target form using the address information found in the symbol table. In effect, the first pass performs synthesis of the target program. The first pass constructs an intermediate representation of the source program for use by the second pass as shown in figure. This representation consists of two main components—data structures, e.g. the symbol table, and a processed form of the source program. The Tasks performed by the passes of a two pass assembler are as follows: Separate the symbol, mnemonic, opcode and operand.
  • 2. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 2 2. Build Symbol Table. 3. Perform LC Processing. 4. Construct Intermediate Representation. • Pass II: 1. Process IR to synthesize the target program. Pass I performs analysis of the source program and the synthesis of the intermediate representation while Pass II processes the intermediate representation to synthesize the target program. Pass I uses the following data structures: OPTAB : A table of machine opcodes and related information SYMTAB : Symbol table LITTAB : A table of literals used in the program. • OPTAB contains the fields mnemonic opcode, class and mnemonic info. The class indicates whether the opcode corresponds to an IS (Imperative statement), DL(Declaration statement) or AD (Assembler directives). If an imperative statement then the mnemonic info field contains the pair (mnemonic opcode, instruction length) else it contains the id of a routine to handle the declaration or directive statement. • SYTAB entry contains the fields address and length. • LITTAB entry contains the fields literal and address. Processing of an assembly statement: • Begins with the processing of label field. • If label fields contains a symbol, the symbol and the value in LC is copied into a new entry of SYMTAB. • For OPTAB entry, the class field of entry is examined to determine whether the mnemonics belongs to the class of imperative, declaration or assembler directive statements. • In case of imperative statement, the length the machine instructions is simply added to LC and length is also entered in the SYMTAB. • For declaration or assembler directives statements, the routine is mentioned in the mnemonic info field is called to perform appropriate processing of the statement.
  • 3. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 3 • The pass I use the LITTAB (Literal Table) to collect all literals used in a program. Awareness of different literal pools is maintained using the auxiliary table POOLTAB. This table contains the literal number of the starting literal of each literal pool. At any stage, the current literal pool is the last pool in LITTAB. On encountering an LTORG statement or END statement, literals in the current pool are allocated addresses starting with the current value in LC and LC is appropriately incremented. Algorithm for Pass I 1. location_counter := 0 pooltable_ptr := 1 POOLTAB[1] := 1 litertable_ptr := 1 2. While next statement is not end statement a. If label is present then this_label := symbol in label field Enter (this_label, location_counter) in SYMTAB b. If LTROG statement then i. Process literals LITTAB[POOLTAL[pooltable_ptr]]… LITTAB[literaltable_ptr -1] to allocate memory and put the address in the address field. Update location_counter accordingly. ii. Pooltable_ptr := pooltable_ptr + 1 iii. POOLTAB[pooltable_ptr] := literaltable_ptr c. If START or ORIGIN statement then location_counter := value specified in the operand field d. If an EQU statement then i. this_address := value of < address specification ii. Correct symbol table entry This_label (this_label, this_address) e. If a declaration statement then
  • 4. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 4 i. code := code of the declaration statement ii. size := size of memory area required by DS or DC iii. location_counter := location_counter + size iv. Generate IC (DL, code) f. If an imperative statement then i. code := machine opcode from OPTAB ii. location_counter := location_counter + instruction length from OPTAB iii. If operand is literal then this_literal := literal in operand field LITTAB [literaltable_ptr] := this_literal Literaltable_ptr := literaltable_ptr + 1 Else (i.e. operand is a symbol) this_entry := SYMTAB entry number of operands Generate IC (IS, code) (S, this_entry) 3. Processing of end statement i. Perform step(2) ii. Generate intermediate code IC (AD, 02) iii. Go to Pass II.
  • 5. System Programming Walchand Institute of Technology Figure: Example to generate intermediate representation using Pass I of two pass Input: START 200 MOVER MOVEM LOOP MOVER MOVER ADD BC LTORG ='5' ='1' NEXT SUB BC Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Figure: Example to generate intermediate representation using Pass I of two pass assembler START 200 MOVER AREG, ='5' MOVEM AREG, A MOVER AREG, A MOVER CREG, B CREG, ='1' ANY, NEXT LTORG AREG, ='1' LT, BACK Sunita M. Dol, CSE Dept Page 5 Figure: Example to generate intermediate representation using Pass I of two pass
  • 6. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 6 LASTSTOP ORIGIN LOOP+2 MULT CREG, B ORIGIN LAST+1 A DS 1 BACK EQU LOOP B DS 2 END ='1' Output: Symbol Table 0 A 211 1 1 LOOP 202 1 2 B 212 2 3 NEXT 208 1 4 BACK 202 1 5 LAST 210 1 6 =’1’ 215 1 Literal Table 0 =’5’ 206 1 1 =’1’ 207 1 2 =’1’ 214 1 Intermediate Representation 0 (AD, 01) (C, 200) 200 (IS, 04) (1) (L, 00) 201 (IS, 05) (1) (S, 00) 202 (IS, 04) (1) (S, 00) 203 (IS, 04) (3) (S, 02) 204 (IS, 01) (3) (L, 01) 205 (IS, 07) (6) (S, 03)
  • 7. System Programming Sunita M. Dol, CSE Dept Walchand Institute of Technology, Solapur Page 7 206 (AD, 05) (L, 00) (L, 01) 208 (IS, 02) (1) (L, 02) 209 (IS, 07) (1) (S, 04) 210 (IS, 00) 210 (AD, 03) (S, 01) + (C, 2) 204 (IS, 03) (3) (S, 02) 205 (AD, 03) (S, 05) + (C, 1) 211 (DL, 02) (C, 1) 212 (AD, 04) (S, 01) 212 (DL, 02) (C, 2) 214 (AD, 02) (L, 02) 215 Conclusion: Location counter processing is performed in the pass-I and symbols defined in the program are entered into the symbol table. Pass-I performs the analysis of source program. Pass I: Separate the symbol, mnemonic, opcode and operand. Build Symbol Table. Perform LC Processing. Construct Intermediate Representation. Thus the pass-I of two pass assembler is implemented in C-language.