SlideShare a Scribd company logo
1 of 20
WALCHAND INSTITUTE OF TECHNOLOGY, SOLAPUR
PRESENTING A SEMINAR ON
TWO PASS ASSEMBLERS
TWO PASS ASSEMBLER
• Processing the source program into two passes.
• The internal tables and subroutines that are used only during Pass 1.
• The SYMTAB, LITTAB, and OPTAB are used by both passes.
• The main problems to assemble a program in one pass involves
forward references.
Pass 1
Forward references
table String storage
buffer Partially
configured object file
Assembly
Language
Pass 2 Machine
Language
• PASS 1
• Assign addresses to all statements in the program.
• Addresses of symbolic labels are stored.
• Some assemble directives will be processed.
• PASS 2
• Translate opcode and symbolic operands.
• Generate data values defined by BYTE,WORD etc.
• Assemble directives will be processed.
• Write the object program and assembly listing.
DATA STRUCTURES
• Two major data structures:
• Operation Code Table (OPTAB): is used to look up mnemonic operation
codes and translate them to their machine language equivalents
• Symbol Table (SYMTAB): is used to store values (addresses) assigned to
labels
• Variable:
• Location Counter (LOCCTR) is used to help the assignment of addresses
• LOCCTR is initialized to the beginning address specified in the START
statement
• The length of the assembled instruction or data area to be generated is
added to LOCCTR
Algorithm for Pass 1 of Assembler(3/1)
read first input line
if OPCODE=‘START’ then
begin
save #[OPERAND] as starting address
initialize LOCCTR to starting address
write line to intermediate file
read next input line
end
else
initialize LOCCTR to 0
while OPCODE≠’END’ do
begin
if this is not a comment line then
begin
if there is a symbol in the LABEL field then
Algorithm for Pass 1 of Assembler(3/2)
begin
search SYMTAB for LABEL
if found then
set error flag (duplicate symbol)
else
insert (LABEL, LOCCTR) into SYMTAB
end {if symbol}
search OPTAB for OPCODE
if found then
add 3 {instruction length} to LOCCTR
else if OPCODE=‘WORD’ then
add 3 to LOCCTR
else if OPCODE=‘RESW’ then
add 3 * #[OPERAND] to LOCCTR
Algorithm for Pass 1 of Assembler(3/3)
else if OPCODE=‘RESB’ then
add #[OPERAND] to LOCCTR
else if OPCODE=‘BYTE’ then
begin
find length of constant in bytes
add length to LOCCTR
end {if BYTE}
else
set error flag (invalid operation code)
end {if not a comment}
write line to intermediate file
read next input line
end {while not END}
Write last line to intermediate file
Save (LOCCTR-starting address) as program length
Algorithm for Pass 2 of Assembler(3/1)
read first input line (from intermediate file)
If OPCODE=‘START’ then
begin
write listing line
read next input line
end {if START}
Write Header record to object program
Initialize first Text record
While OPCODE≠ ‘END’ do
begin
if this is not a comment line then
begin
search OPTAB for OPCODE
if found then
begin
Algorithm for Pass 2 of Assembler(3/2)
if there is a symbol in OPERAND field then
begin
search SYMTAB for OPERAND
if found then
store symbol value as operand address
else
begin
store 0 as operand address
set error flag (undefined symbol)
end
end {if symbol}
else
store 0 as operand address
assemble the object code instruction
end {if opcode found}
Algorithm for Pass 2 of Assembler(3/3)
else if OPCODE=‘BYTE’ or ‘WORD’ then
convert constant to object code
if object code will not fit into the current Text record then
begin
write Text record to object program
initialize new Text record
end
add object code to Text record
end {if not comment}
write listing line
read next input line
end {while not END}
write last Text record to object program
Write End record to object program
Write last listing line
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char *code[9][4]={
{"PRG1","START","",""},
{"","USING","*","15"},
{"","L","",""},
{"","A","",""},
{"","ST","",""},
{"FOUR","DC","F",""},
{"FIVE","DC","F",""},
{"TEMP","DS","1F",""},
{"","END","",""}
};
char av[2],avail[15]={'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'};
int i,j,k,count[3],lc[9]={0,0,0,0,0,0,0,0,0},loc=0;
clrscr();
Program
printf("----------------------------------------------------n");
printf("LABELttOPCODEn");
printf("----------------------------------------------------nn");
for(i=0;i<=8;i++)
{
for(j=0;j<=3;j++)
{
printf("%stt",code[i][j]);
}
j=0;
printf("n");
}
getch();
printf("-----------------------------------------------------");
printf("nVALUES FOR LC : nn");
for(j=0;j<=8;j++)
{
if((strcmp(code[j][1],"START")!=0)&&(strcmp(code[j][1],"USING")!=0)&&(strcmp(code[j][1],"L")!=0))
lc[j]=lc[j-1]+4;
printf("%dt",lc[j]);
}
printf("nnSYMBOL TABLE:n----------------------------------------------------n");
printf("SYMBOLttVALUEttLENGTHttR/A");
printf("n----------------------------------------------------n");
for(i=0;i< 9;i++)
{
if(strcmp(code[i][1],"START")==0)
{
printf("%stt%dtt%dtt%cn",code[i][0],loc,4,'R');
}
else
if(strcmp(code[i][0],"")!=0)
{
printf("%stt%dtt%dtt%cn",code[i][0],loc,4,'R');
loc=4+loc;
}
else
if(strcmp(code[i][1],"USING")==0)
{
}
else
{
loc=4+loc;
printf("----------------------------------------------------");
printf("nnBASE TABLE:n-------------------------------------------------------n");
printf("REG NOttAVAILIBILITYtCONTENTS OF BASE TABLE");
printf("n-------------------------------------------------------n");
for(j=0;j<=8;j++)
{
if(strcmp(code[j][1],"USING")!=0)
{
}
else
{
strcpy(av,code[j][3]);
}
}
count[0]=(int)av[0]-48;
count[1]=(int)av[1]-48;
count[2]=count[0]*10+count[1];
avail[count[2]-1]='Y';
for(k=0;k< 16;k++)
{
printf(" %dtt %cn",k,avail[k-1]);
}
printf("-------------------------------------------------------n");
printf("Continue..??");
getchar();
printf("PASS2 TABLE:nn");
printf("LABELttOP1ttLCtt");
printf("n----------------------------------------------------n");
loc=0;
for(i=0;i<=8;i++)
{
for(j=0;j<=3;j++)
{
printf("%stt",code[i][j]);
}
j=0;
printf("n");
}
printf("-----------------------------------------------------");
getch();
----------------------------------------------------
LABEL OPCODE
----------------------------------------------------
PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END
-----------------------------------------------------
VALUES FOR LC :
0 0 0 4 8 12 16 20 24
OUTPUT
SYMBOL TABLE:
----------------------------------------------------
SYMBOL VALUE LENGTH R/A
----------------------------------------------------
PRG1 0 4 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R
----------------------------------------------------
BASE TABLE:
-------------------------------------------------------
REG NO AVAILIBILITY CONTENTS OF BASE TABLE
-------------------------------------------------------
0
1 N
2 N
3 N
4 N
5 N
6 N
7 N
8 N
9 N
10 N
11 N
12 N
13 N
Continue..??
PASS2 TABLE:
LABEL OP1 LC
----------------------------------------------------
PRG1 START
USING * 15
L
A
ST
FOUR DC F
FIVE DC F
TEMP DS 1F
END
-----------------------------------------------------
Two pass Assembler

More Related Content

What's hot

System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
babyparul
 
Flow oriented modeling
Flow oriented modelingFlow oriented modeling
Flow oriented modeling
ramyaaswin
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 

What's hot (20)

Macro-processor
Macro-processorMacro-processor
Macro-processor
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Pass Structure of Assembler
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Direct linking loader
Direct linking loaderDirect linking loader
Direct linking loader
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
 
Design notation
Design notationDesign notation
Design notation
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Code generation
Code generationCode generation
Code generation
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Flow oriented modeling
Flow oriented modelingFlow oriented modeling
Flow oriented modeling
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Loaders
LoadersLoaders
Loaders
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOL
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 

Viewers also liked (6)

Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Assembler
AssemblerAssembler
Assembler
 

Similar to Two pass Assembler

35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
Naveen Kumar
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
vamsiyadav39
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
Abdul Khan
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
afa reg
 

Similar to Two pass Assembler (20)

module 4.docx
module 4.docxmodule 4.docx
module 4.docx
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
 
Compreport
CompreportCompreport
Compreport
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 
assembler-ppt.pdf
assembler-ppt.pdfassembler-ppt.pdf
assembler-ppt.pdf
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 
Mis4200notes8 2
Mis4200notes8 2Mis4200notes8 2
Mis4200notes8 2
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Handout#10
Handout#10Handout#10
Handout#10
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 
lect 5
lect 5lect 5
lect 5
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
SPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptxSPOS UNIT1 PPTS (1).pptx
SPOS UNIT1 PPTS (1).pptx
 

More from Satyamevjayte Haxor (16)

Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Patterns
PatternsPatterns
Patterns
 
Uml class Diagram
Uml class DiagramUml class Diagram
Uml class Diagram
 
Uml Common Mechanism
Uml Common MechanismUml Common Mechanism
Uml Common Mechanism
 
Types and roles
Types and rolesTypes and roles
Types and roles
 
States machine
States machineStates machine
States machine
 
What is symbol table?
What is symbol table?What is symbol table?
What is symbol table?
 
Lexical
LexicalLexical
Lexical
 
Linker
LinkerLinker
Linker
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
Nested micro
Nested microNested micro
Nested micro
 
Multiplier control unit
Multiplier control unitMultiplier control unit
Multiplier control unit
 
Control unit design
Control unit designControl unit design
Control unit design
 
Compilers
CompilersCompilers
Compilers
 
Keyword Presentation
Keyword PresentationKeyword Presentation
Keyword Presentation
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

Two pass Assembler