6. Assembly Process
Pass 1 :Completely scan .asm file. 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 table that 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
12. • 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
13. Pass1 of assembler
Convert .asm file into .obj fie
Complete scan .asm file to gather information and bulid a 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
14. 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 needed for each instruction or
data element.
SWAPNALI R. PAWAR~(RIT) 14
15. • 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 instruction formats
or invalid operations. However, detailed error checking is done by second pass.
SWAPNALI R. PAWAR~(RIT) 15
16. • 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
17. 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
18. 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
19. • Process Instructions: The assembler reads each instruction, like "MOV" or "ADD."
It translates these human-readable instructions into the corresponding binary
patterns that represent machine instructions. This is where the translation from
assembly language to machine code happens.
• Calculating Offsets: For instructions involving memory, the assembler calculates
the appropriate memory addresses and offsets based on the information from the
first pass and the specific addressing modes used in the instruction.
• Putting It All Together: As the assembler processes each line of code, it builds up
the final machine code sequence, piece by piece. It also handles data definitions,
creating the binary representation for constants and variables.
SWAPNALI R. PAWAR~(RIT) 19
20. • Errors and Warnings: The assembler also performs a more thorough error check
during this pass. If it finds syntax errors or logical errors that weren't caught in the
first pass, it reports them now.
• Finished Product: At the end of the second pass, you have a complete binary
representation of your program that's ready to be executed on the computer's
hardware.
• Think of the second pass as the step where your assembly code truly becomes the
instructions that the computer's CPU can follow. The first pass organized everything,
and the second pass brings it all to life by turning it into the language the machine
understands.
SWAPNALI R. PAWAR~(RIT) 20