SlideShare a Scribd company logo
Chapter 2
Assemblers
Assembly Language Programming
• Writing a program in assembly lang is more
convenient than in machine lang.
• Assembly program is more readable.
• Assembly lang is machine dependent.
• Assembly program is written using
symbols(Mnemonics).
• Assembly program is translated into machine
code before execution.
Assembler
Assembly
Language
Program
Machine
Language
Figure: Assembler
Example:
MOV AX, X
--MOV is a mnemonic opcode.
--AX is a register operand in symbolic form.
--X is a memory operand in symbolic form.
Elements of Assembly Language
1. Mnemonic Operation Code:-
Eliminates the need to memorize numeric
operation code.
2. Symbolic Operands:-
Symbolic names can be used.
3. Data Declarations:-
Data can be declared in any form
Eg: -5, 10.5 etc.
Statement Format
[Label] <Opcode> <operand Spec> [<operand spec>….]
1. Label:- Is optional.
2. Opcode:- Symbolic opcode
3. Operand:- Symbolic name (Register or Memory
variable)
Instruction
Opcode
Assembly
Mnemonic
Remarks
00 STOP Stop Execution
01 ADD Op1  Op1+ Op2
02 SUB Op1  Op1 – Op2
03 MULT Op1  Op1* Op2
04 MOVER CPU Reg  Memory operand
05 MOVEM Memory  CPU Reg
06 COMP Sets Condition Code
07 BC Branch on Condition
08 DIV Op1  Op1/ Op2
09 READ Operand 2  input Value
10 PRINT Output  Operand2
Fig: Mnemonic Operation Codes
Instruction Format
sign opcode reg
operand
memory
operand
Fig: Instruction Format
Assembly Lang to M/C lang Program
1. Find address of variables and labels.
2. Replace Symbolic addr by numeric addr.
3. Replace Symbolic opcodes by machine
opcode.
4. Reserve storage for data.
START 101
READ X
READ Y
MOVER AREG, X
ADD AREG, Y
MOVEM AREG, RESULT
PRINT RESULT
STOP
X DS 1
Y DS 1
RESULT DS 1
END
Fig: Sample program to find X+Y
START 101
READ X
READ Y
MOVER AREG, X
ADD AREG, Y
MOVEM AREG, RESULT
PRINT RESULT
STOP
X DS 1
Y DS 1
RESULT DS 1
END
LC
101
102
103
104
105
106
107
108
109
110
+ 09 0 108
+ 09 0 109
+ 04 1 108
+ 01 1 109
+ 05 0 110
+ 10 0 110
+ 00 0 000
Opcode Register Memory
operand
Variable Address
X 108
Y 109
RESULT 110
Figure: After LC Processing
Required M/C Code
LC Opcode Register Address
101 09 0 108
102 09 0 109
103 04 1 108
104 01 1 109
105 05 0 110
106 10 0 110
107 00 0 000
108
109
110
111
Assembly Language Statement
1. Imperative Statement.
2. Declaration Statement.
3. Assembler Directives.
• Imperative Statements:-
– Indicates an action to be taken during execution of a
program.
– Eg: MOV, ADD, MULT, etc.
• Declaration Statement:-
– To reserve memory for variable.
[Label] DS <constant> eg: X DS 5
[Label] DC ‘<value>’ eg: X DC 3
• Assembler Directives:-
– Instructs the assembler to perform ceratin action during
assembly of a program.
START <constant>
END
Literals & Constants
int z=5;
x = x + 5;
1. Literal cannot be changed during program
execution
2. Literal is more safe and protected than a
constant.
3. Literals appear as a part of the instruction.
Advanced Assembler Directives
• ORIGIN
– ORIGIN <address specification>
• EQU
– <symbol> EQU <address specification>
• LTORG
– Allocates address for literals.
Pass structure of assembler
Pass I Pass II
Intermediate Code
Source
Program
Target
Program
Figure: Overview of Two Pass Assembler
Data Structures
Two Pass Translation
• Handles forward references easily.
• Requires 2 scans of the source program.
• LC processing is performed in the 1st pass and
symbols are stored in the symbol table.
• Second pass synthesis Target Program.
Single Pass Translation
• The problem of forward reference can be
handled using a technique called as back
patching.
START 100
MOVER AREG, X
L1 ADD BREG, ONE
ADD CREG, TEN
STOP
X DC ‘5’
ONE DC ‘1’
TEN DC ‘10’
END
START 100
MOVER AREG, X
L1 ADD BREG, ONE
ADD CREG, TEN
STOP
X DC ‘5’
ONE DC ‘1’
TEN DC ‘10’
END
100 04 1 _ _ _
101 01 2 _ _ _
102 06 3 _ _ _
103 00 0 000
104
105
106
Instruction Address Symbol Making a forward reference
100 X
101 ONE
102 TEN
Figure : TII
Machine Instruction After Backpatching
04 1 104
01 2 105
06 2 106
00 0 000
Design of a Two Pass Assembler
• Pass I:-
1. Separate the symbol, mnemonic, opcode and
operand.
2. Build Symbol Table.
3. Perform LC Processing.
4. Construct Intermediate Representation.
• Pass II:-
1.Process IR to synthesize the target program.
Pass I
• Pass I uses the following data structures
1. Machine Opcode table (OPTAB)
2. Symbol Table (ST)
3. Literal Table (LT)
4. Pool Table (PT)
1. OPTAB contains opcode, class and opcode
length.
2. SYMTAB contains symbol and address.
3. LITTAB contains literal and address.
4. POOLTAB contains starting literal number of
each pool.
START 200
MOVER AREG, =‘5’
MOVEM AREG, X
L1 MOVER BREG, =‘2’
ORIGIN L1+3
LTORG
NEXT ADD AREG,=‘1’
SUB BREG,=‘2’
BC LT, BACK
LTORG
BACK EQU L1
ORIGIN NEXT+5
MULT CREG,=‘4’
STOP
X DS 1
END
LC
200
201
202
205
206
207
208
209
210
211
212
212
213
214
Symbol Address Literal Address Pool Table
0
START 200
MOVER AREG,=‘5’ 200
Symbol Address Literal Address
=‘5’ ---
Pool Table
0
MOVEM AREG,X 201
Symbol Address
X ----
Literal Address
=‘5’ ---
Pool Table
0
L1 MOVER BREG,=‘2’ 202
Symbol Address
X ----
L1 202
Literal Address
=‘5’ ---
=‘2’ ---
Pool Table
0
ORIGIN L1+3 203
Symbol Address
X ----
L1 202
Literal Address
=‘5’ ---
=‘2’ ---
Pool Table
0
LTORG 205
206
Symbol Address
X ----
L1 202
Literal Address
=‘5’ 205
=‘2’ 206
Pool Table
0
2
NEXT ADD AREG, =‘1’ 207
Symbol Address
X ----
L1 202
NEXT 207
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ ----
Pool Table
0
2
SUB BREG,=‘2’ 208
Symbol Address
X ----
L1 202
NEXT 207
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ ----
=‘2’ -----
Pool Table
0
2
BC LT, BACK 209
Symbol Address
X ----
L1 202
NEXT 207
BACK ----
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ ----
=‘2’ ----
Pool Table
0
2
LTORG 210
211
Symbol Address
X ----
L1 202
NEXT 207
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
Pool Table
0
2
4
BACK EQU L1 212
Symbol Address
X ----
L1 202
NEXT 207
BACK 202
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
Pool Table
0
2
4
ORIGIN NEXT+5 213
Symbol Address
X ----
L1 202
NEXT 207
BACK 202
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
Pool Table
0
2
4
MULT CREG,=‘4’ 212
Symbol Address
X ----
L1 202
NEXT 207
BACK 202
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
=‘4’ ----
Pool Table
0
2
4
STOP 213
Symbol Address
X ----
L1 202
NEXT 207
BACK 202
Pool Table
0
2
4
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
=‘4’ ----
X DS 1 214
Symbol Address
X 214
L1 202
NEXT 207
BACK 202
Pool Table
0
2
4
END
Symbol Address
X 214
L1 202
NEXT 207
BACK 202
Pool Table
0
2
4
5
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
=‘4’ ----
Literal Address
=‘5’ 205
=‘2’ 206
=‘1’ 210
=‘2’ 211
=‘4’ 215

More Related Content

What's hot

System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
Dattatray Gandhmal
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
SARASWATHI S
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit IIManoj Patil
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
Bansari Shah
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Loaders
LoadersLoaders
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
Dhruv Sabalpara
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
Saranya1702
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
Bhavik Vashi
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
Meghaj Mallick
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
Saranya1702
 
Language processors
Language processorsLanguage processors
Language processors
Ganesh Wedpathak
 
Unit 3
Unit 3Unit 3
Unit 3
pm_ghate
 
Unit 2
Unit 2Unit 2
Unit 2
pm_ghate
 

What's hot (20)

System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Pass Structure of Assembler
 
Loaders
LoadersLoaders
Loaders
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
Language processors
Language processorsLanguage processors
Language processors
 
Unit 3
Unit 3Unit 3
Unit 3
 
Pass 1 flowchart
Pass 1 flowchartPass 1 flowchart
Pass 1 flowchart
 
Unit 2
Unit 2Unit 2
Unit 2
 

Similar to Assemblers

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
Ashwini864432
 
Spr ch-02
Spr ch-02Spr ch-02
Spr ch-02
Vasim Pathan
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
Bhatt Balkrishna
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
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
Rai University
 
Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimonSisimon Soman
 
Cisco CCENT Cram Notes
Cisco CCENT Cram NotesCisco CCENT Cram Notes
Cisco CCENT Cram Notes
Vijayanand Yadla
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
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
Rai University
 
Ccna cheat sheet
Ccna cheat sheetCcna cheat sheet
Ccna cheat sheetaromal4frnz
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
Tirumalesh Nizampatnam
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
FarrukhMuneer2
 
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
Rai University
 
Instruction types
Instruction typesInstruction types
Instruction types
JyotiprakashMishra18
 
[ASM] Lab1
[ASM] Lab1[ASM] Lab1
[ASM] Lab1
Nora Youssef
 

Similar to Assemblers (20)

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
 
Spr ch-02
Spr ch-02Spr ch-02
Spr ch-02
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 
Chap 01[1]
Chap 01[1]Chap 01[1]
Chap 01[1]
 
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
 
Sp chap2
Sp chap2Sp chap2
Sp chap2
 
Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimon
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Cisco CCENT Cram Notes
Cisco CCENT Cram NotesCisco CCENT Cram Notes
Cisco CCENT Cram Notes
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
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
 
Ccna cheat sheet
Ccna cheat sheetCcna cheat sheet
Ccna cheat sheet
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
 
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
 
Instruction types
Instruction typesInstruction types
Instruction types
 
[ASM] Lab1
[ASM] Lab1[ASM] Lab1
[ASM] Lab1
 
Assembler
AssemblerAssembler
Assembler
 

Recently uploaded

Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

Assemblers

  • 2. Assembly Language Programming • Writing a program in assembly lang is more convenient than in machine lang. • Assembly program is more readable. • Assembly lang is machine dependent. • Assembly program is written using symbols(Mnemonics). • Assembly program is translated into machine code before execution.
  • 4. Example: MOV AX, X --MOV is a mnemonic opcode. --AX is a register operand in symbolic form. --X is a memory operand in symbolic form.
  • 5. Elements of Assembly Language 1. Mnemonic Operation Code:- Eliminates the need to memorize numeric operation code. 2. Symbolic Operands:- Symbolic names can be used. 3. Data Declarations:- Data can be declared in any form Eg: -5, 10.5 etc.
  • 6. Statement Format [Label] <Opcode> <operand Spec> [<operand spec>….] 1. Label:- Is optional. 2. Opcode:- Symbolic opcode 3. Operand:- Symbolic name (Register or Memory variable)
  • 7. Instruction Opcode Assembly Mnemonic Remarks 00 STOP Stop Execution 01 ADD Op1  Op1+ Op2 02 SUB Op1  Op1 – Op2 03 MULT Op1  Op1* Op2 04 MOVER CPU Reg  Memory operand 05 MOVEM Memory  CPU Reg 06 COMP Sets Condition Code 07 BC Branch on Condition 08 DIV Op1  Op1/ Op2 09 READ Operand 2  input Value 10 PRINT Output  Operand2 Fig: Mnemonic Operation Codes
  • 8. Instruction Format sign opcode reg operand memory operand Fig: Instruction Format
  • 9. Assembly Lang to M/C lang Program 1. Find address of variables and labels. 2. Replace Symbolic addr by numeric addr. 3. Replace Symbolic opcodes by machine opcode. 4. Reserve storage for data.
  • 10. START 101 READ X READ Y MOVER AREG, X ADD AREG, Y MOVEM AREG, RESULT PRINT RESULT STOP X DS 1 Y DS 1 RESULT DS 1 END Fig: Sample program to find X+Y
  • 11. START 101 READ X READ Y MOVER AREG, X ADD AREG, Y MOVEM AREG, RESULT PRINT RESULT STOP X DS 1 Y DS 1 RESULT DS 1 END LC 101 102 103 104 105 106 107 108 109 110 + 09 0 108 + 09 0 109 + 04 1 108 + 01 1 109 + 05 0 110 + 10 0 110 + 00 0 000 Opcode Register Memory operand
  • 12. Variable Address X 108 Y 109 RESULT 110 Figure: After LC Processing
  • 13. Required M/C Code LC Opcode Register Address 101 09 0 108 102 09 0 109 103 04 1 108 104 01 1 109 105 05 0 110 106 10 0 110 107 00 0 000 108 109 110 111
  • 14. Assembly Language Statement 1. Imperative Statement. 2. Declaration Statement. 3. Assembler Directives.
  • 15. • Imperative Statements:- – Indicates an action to be taken during execution of a program. – Eg: MOV, ADD, MULT, etc. • Declaration Statement:- – To reserve memory for variable. [Label] DS <constant> eg: X DS 5 [Label] DC ‘<value>’ eg: X DC 3 • Assembler Directives:- – Instructs the assembler to perform ceratin action during assembly of a program. START <constant> END
  • 16. Literals & Constants int z=5; x = x + 5; 1. Literal cannot be changed during program execution 2. Literal is more safe and protected than a constant. 3. Literals appear as a part of the instruction.
  • 17. Advanced Assembler Directives • ORIGIN – ORIGIN <address specification> • EQU – <symbol> EQU <address specification> • LTORG – Allocates address for literals.
  • 18. Pass structure of assembler Pass I Pass II Intermediate Code Source Program Target Program Figure: Overview of Two Pass Assembler Data Structures
  • 19. Two Pass Translation • Handles forward references easily. • Requires 2 scans of the source program. • LC processing is performed in the 1st pass and symbols are stored in the symbol table. • Second pass synthesis Target Program.
  • 20. Single Pass Translation • The problem of forward reference can be handled using a technique called as back patching.
  • 21. START 100 MOVER AREG, X L1 ADD BREG, ONE ADD CREG, TEN STOP X DC ‘5’ ONE DC ‘1’ TEN DC ‘10’ END
  • 22. START 100 MOVER AREG, X L1 ADD BREG, ONE ADD CREG, TEN STOP X DC ‘5’ ONE DC ‘1’ TEN DC ‘10’ END 100 04 1 _ _ _ 101 01 2 _ _ _ 102 06 3 _ _ _ 103 00 0 000 104 105 106 Instruction Address Symbol Making a forward reference 100 X 101 ONE 102 TEN Figure : TII
  • 23. Machine Instruction After Backpatching 04 1 104 01 2 105 06 2 106 00 0 000
  • 24. Design of a Two Pass Assembler • Pass I:- 1. Separate the symbol, mnemonic, opcode and operand. 2. Build Symbol Table. 3. Perform LC Processing. 4. Construct Intermediate Representation. • Pass II:- 1.Process IR to synthesize the target program.
  • 25. Pass I • Pass I uses the following data structures 1. Machine Opcode table (OPTAB) 2. Symbol Table (ST) 3. Literal Table (LT) 4. Pool Table (PT)
  • 26. 1. OPTAB contains opcode, class and opcode length. 2. SYMTAB contains symbol and address. 3. LITTAB contains literal and address. 4. POOLTAB contains starting literal number of each pool.
  • 27. START 200 MOVER AREG, =‘5’ MOVEM AREG, X L1 MOVER BREG, =‘2’ ORIGIN L1+3 LTORG NEXT ADD AREG,=‘1’ SUB BREG,=‘2’ BC LT, BACK LTORG BACK EQU L1 ORIGIN NEXT+5 MULT CREG,=‘4’ STOP X DS 1 END LC 200 201 202 205 206 207 208 209 210 211 212 212 213 214
  • 28. Symbol Address Literal Address Pool Table 0 START 200 MOVER AREG,=‘5’ 200 Symbol Address Literal Address =‘5’ --- Pool Table 0
  • 29. MOVEM AREG,X 201 Symbol Address X ---- Literal Address =‘5’ --- Pool Table 0 L1 MOVER BREG,=‘2’ 202 Symbol Address X ---- L1 202 Literal Address =‘5’ --- =‘2’ --- Pool Table 0
  • 30. ORIGIN L1+3 203 Symbol Address X ---- L1 202 Literal Address =‘5’ --- =‘2’ --- Pool Table 0 LTORG 205 206 Symbol Address X ---- L1 202 Literal Address =‘5’ 205 =‘2’ 206 Pool Table 0 2
  • 31. NEXT ADD AREG, =‘1’ 207 Symbol Address X ---- L1 202 NEXT 207 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ ---- Pool Table 0 2 SUB BREG,=‘2’ 208 Symbol Address X ---- L1 202 NEXT 207 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ ---- =‘2’ ----- Pool Table 0 2
  • 32. BC LT, BACK 209 Symbol Address X ---- L1 202 NEXT 207 BACK ---- Literal Address =‘5’ 205 =‘2’ 206 =‘1’ ---- =‘2’ ---- Pool Table 0 2 LTORG 210 211 Symbol Address X ---- L1 202 NEXT 207 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 Pool Table 0 2 4
  • 33. BACK EQU L1 212 Symbol Address X ---- L1 202 NEXT 207 BACK 202 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 Pool Table 0 2 4 ORIGIN NEXT+5 213 Symbol Address X ---- L1 202 NEXT 207 BACK 202 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 Pool Table 0 2 4
  • 34. MULT CREG,=‘4’ 212 Symbol Address X ---- L1 202 NEXT 207 BACK 202 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 =‘4’ ---- Pool Table 0 2 4 STOP 213 Symbol Address X ---- L1 202 NEXT 207 BACK 202 Pool Table 0 2 4 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 =‘4’ ----
  • 35. X DS 1 214 Symbol Address X 214 L1 202 NEXT 207 BACK 202 Pool Table 0 2 4 END Symbol Address X 214 L1 202 NEXT 207 BACK 202 Pool Table 0 2 4 5 Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 =‘4’ ---- Literal Address =‘5’ 205 =‘2’ 206 =‘1’ 210 =‘2’ 211 =‘4’ 215