10.Design Of Two Pass Assembler in system software.pdf

2,845 views 21 slides Mar 22, 2024
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

Design Of Two Pass Assembler


Slide Content

Design Of Two Pass
Assembler
BY SWAPNALI R. PAWAR
SWAPNALI R. PAWAR~(RIT) 1

SWAPNALI R. PAWAR~(RIT) 2

SWAPNALI R. PAWAR~(RIT) 3

SWAPNALI R. PAWAR~(RIT) 4

SWAPNALI R. PAWAR~(RIT) 5

Assembly Process
Pass 1 :Completely scan .asmfile. Finds all labels and calculates corresponding address, stores
different type data in different data structure such as symbol table ,Literal Table and pool Table.
Pass2: Convert all the instructions into machine language format.
Symbol Table : Stores information about assembly program such as data, variables ,instructions and
addresses
Literal table keeps track of constants (like numbers or strings) used in the program.
Pool tablethat keeps track of the locations where constants are used in the program. It's like a
"waiting area" for constants. When a constant is encountered in the code, the assembler adds its
address to the pool table.This helps in generating the correct addresses for these constants during
the second pass.
SWAPNALI R. PAWAR~(RIT) 6

SWAPNALI R. PAWAR~(RIT) 7

SWAPNALI R. PAWAR~(RIT) 8

SWAPNALI R. PAWAR~(RIT) 9

SWAPNALI R. PAWAR~(RIT) 10

SWAPNALI R. PAWAR~(RIT) 11

•Literal Table:
•Keeps track of constants used in the program.
•Assigns symbols to each constant and stores their values.
•Helps the assembler manage constants and replace them with values in the
second pass.
•Pool Table:
•Keeps track of locations where constants are used.
•Acts like a "waiting area" for constants.
•Stores addresses of constants encountered in the code.
•Aids in generating correct addresses for constants during the second pass.
SWAPNALI R. PAWAR~(RIT) 12

Pass1 of assembler
Convert .asmfile into .objfie
Complete scan .asmfile to gather information and bulida symbol table , literal table, pool table.
In a two-pass assembler, the first pass performs a scan of the entire assembly source code to
gather information and build a symbol table.
The primary goal of the first pass is to identify labels, assign memory addresses to instructions
This information is required for the second pass of the assembler to generate the final machine
code.
SWAPNALI R. PAWAR~(RIT) 13

operations performed in pass 1
Label Handling:
The assembler identifies and processes labels (symbolic names for memory addresses). It
records these memory addresses in the symbol table.
Address Calculation:
For instructions and data, the assembler calculates the memory addresses where they will be
placed in memory. This involves counting the number of bytes neededfor each instruction or
data element.
SWAPNALI R. PAWAR~(RIT) 14

•Macro Expansion:
•If the assembly language supports macros (predefined sequences of instructions),
the first pass may expand these macros to their corresponding instructions.
•Directive Processing:
Directives that allocate memory space, define variables, or set up program sections
are processed. The assembler reserves memory for data and records information
about program sections.
•Error Checking:
•Basic syntax and semantic errors are checked, such as incorrect instructionformats
or invalid operations. However, detailed error checking is done by second pass.
SWAPNALI R. PAWAR~(RIT) 15

•Intermediate Code Generation:
•An intermediate representation of the assembly code is created. This
intermediate code is used in the second pass to generate the final machine code.
•Symbol Table Construction:
•As the assembler encounters labels and instructions, it builds a symbol table. The
symbol table stores the labels along with their corresponding memory addresses.
•Literal Processing, Literal table ,pool table:
•Literals (constant values used in the code) are identified and assigned memory
addresses.
•The first pass creates the groundwork for the assembler's understanding of the
program's structure and memory allocation. Once the first pass is complete, the
assembler has gathered enough information to perform the second pass, during
which it generates the actual machine code.
SWAPNALI R. PAWAR~(RIT) 16

Pass 2 of assembler
After the first pass has collected all the pieces (information about labels, addresses, instructions,
etc.), the second pass takes those pieces and arranges them correctly to create the final picture,
which is the machine code that the computer can understand and execute.
It's the step where the actual translation from assembly code to machine code happens.
SWAPNALI R. PAWAR~(RIT) 17

Break down the second pass of a
two-pass assembler in simple terms:
Information from First Pass: In the first pass, the assembler gathered information about labels,
addresses, instructions, and data. This information is stored in a symbol table and other data
structures.
Replacing Labels: Remember those labels we used to mark different parts of the code? The
assembler works on your code line by line. When it encounters a label, it looks up its address in
the symbol table and replaces the label with the actual memory address.
SWAPNALI R. PAWAR~(RIT) 18

•ProcessInstructions:Theassemblerreadseachinstruction,like"MOV"or"ADD."
Ittranslatesthesehuman-readableinstructionsintothecorrespondingbinary
patternsthatrepresentmachineinstructions.Thisiswherethetranslationfrom
assemblylanguagetomachinecodehappens.
•CalculatingOffsets:Forinstructionsinvolvingmemory,theassemblercalculates
theappropriatememoryaddressesandoffsetsbasedontheinformationfromthe
firstpassandthespecificaddressingmodesusedintheinstruction.
•PuttingItAllTogether:Astheassemblerprocesseseachlineofcode,itbuildsup
thefinalmachinecodesequence,piecebypiece.Italsohandlesdatadefinitions,
creatingthebinaryrepresentationforconstantsandvariables.
SWAPNALI R. PAWAR~(RIT) 19

•ErrorsandWarnings:Theassembleralsoperformsamorethorougherrorcheck
duringthispass.Ifitfindssyntaxerrorsorlogicalerrorsthatweren'tcaughtinthe
firstpass,itreportsthemnow.
•FinishedProduct:Attheendofthesecondpass,youhaveacompletebinary
representationofyourprogramthat'sreadytobeexecutedonthecomputer's
hardware.
•Thinkofthesecondpassasthestepwhereyourassemblycodetrulybecomesthe
instructionsthatthecomputer'sCPUcanfollow.Thefirstpassorganizedeverything,
andthesecondpassbringsitalltolifebyturningitintothelanguagethemachine
understands.
SWAPNALI R. PAWAR~(RIT) 20

Thank You !
SWAPNALI R. PAWAR~(RIT) 21