You are on page 1of 5

MULTI PASS ASSEMBLER

INTRODUCTION

Multi pass assembler means more than one pass is used by assembler. Multi pass
assembler is used to eliminate forward references in symbol definition. It creates a number of
passes that is necessary to process the definition of symbols. Multi pass assembler does the
work in two pass by resolving the forward references.

First pass

Scans the code

Validates the tokens

Creates a symbol table

Second Pass

Solves forward references

Converts the code to the machine

IMPLEMENTATION

A programming language that is one step away from machine language. Each
assembly language statement is translated into one machine instruction by the assembler.
Programmers must be well versed in the computer's architecture, and, undocumented
assembly language programs are difficult to maintain. It is hardware dependent; there is a
different assembly language for each CPU series.

Pass 1

Assign addresses to all statements in the program

Save the values assigned to all labels for use in Pass 2

1
Perform some processing of assembler directives

Pass 2

Assemble instructions

Generate data values defined by BYTE, WORD

Perform processing of assembler directives not done in Pass 1

MULTI PASS ASSEMBLER OVER SOURCE CODE

A two-pass assembler performs two sequential scans over the source code:

Pass 1: symbols and literals are defined

Pass 2: object program is generated

Parsing: moving in program lines to pull out op-codes and operands

DATA STRUCTURES

Location counter (LC): points to the next location where the code will be placed

Op-code translation table: contains symbolic instructions, their lengths and their
op-codes (or subroutine to use for translation)

Symbol table (ST): contains labels and their values

String storage buffer (SSB): contains ASCII characters for the strings

Forward references table (FRT): contains pointer to the string in SSB and offset
where its value will be inserted in the object code

2
A simple two pass assembler

NUMBER OF PASSES COMPARISON


There are two types of assemblers based on how many passes through the source are
needed (how many times the assembler reads the source) to produce the executable program.

One-pass assemblers go through the source code once. Any symbol used before it
is defined will require "errata" at the end of the object code (or, at least, no earlier
than the point where the symbol is defined) telling the linker or the loader to "go
back" and overwrite a placeholder which had been left where the as yet undefined
symbol was used.

Multi-pass assemblers create a table with all symbols and their values in the first
passes, then use the table in later passes to generate code.

EXAMPLE

In the following code snippet a one-pass assembler would be able to determine the
address of the backward reference BKWD when assembling statement S2, but would not be
able to determine the address of the forward reference FWD when assembling the branch
statement S1; indeed FWD may be undefined. A two-pass assembler would determine both
addresses in pass 1, so they would be known when generating code in pass 2,

S1 B FWD

...

FWD EQU *

...

3
BKWD EQU *

...

S2 B BKWD

In both cases, the assembler must be able to determine the size of each instruction on
the initial passes in order to calculate the addresses of subsequent symbols. This means that if
the size of an operation referring to an operand defined later depends on the type or distance
of the operand, the assembler will make a pessimistic estimate when first encountering the
operation, and if necessary pad it with one or more "no-operation" instructions in a later pass
or the errata. In an assembler with peephole optimization, addresses may be recalculated
between passes to allow replacing pessimistic code with code tailored to the exact distance
from the target.

The original reason for the use of one-pass assemblers was speed of assembly often
a second pass would require rewinding and rereading the program source on tape or rereading
a deck of cards or punched paper tape. With modern computers this has ceased to be an issue.
The advantage of the multi-pass assembler is that the absence of errata makes the linking
process (or the program load if the assembler directly produces executable code) faster.

APPLICATIONS

Assembly language is typically used in a system's boot code, the low-level code
that initializes and tests the system hardware prior to booting the operating system
and is often stored in ROM. (BIOS on IBM-compatible PC systems and CP/M is
an example.)

Some compilers translate high-level languages into assembly first before fully
compiling, allowing the assembly code to be viewed for debugging and
optimization purposes.

Relatively low-level languages, such as C, allow the programmer to embed


assembly language directly in the source code. Programs using such facilities,
such as the Linux kernel, can then construct abstractions using different assembly

4
language on each hardware platform. The system's portable code can then use
these processor-specific components through a uniform interface.

Assembly language is used to enhance speed of execution, especially in early


Personal Computers with limited processing power and RAM.

CONCLUSION

Sometimes, the first pass of an extreme two-pass assembler produces an output file
which is then read in by the second pass. The advantage of this is that the first pass can
record, with each line of input, the positions of some or all of the lexemes on that line and
some of the results of parsing. For example, in the example assembly language, each line
might be sent from one pass to the next with a record indicating whether the line was a
definition, or a statement, and, for statements, whether the line contained a label and what the
value of the location counter was prior to processing that line. The use of such an
intermediate file can almost completely eliminate redundant computations in the two passes,
but it adds to the input/output burden of the system.

The advantage of writing assemblers with a separate procedure for each pass is that
this leads to assemblers which run very fast, since no flag must be tested to determine what to
evaluate. On the other hand, this approach results in two very similar procedures which must
be maintained in parallel, and which occupy almost twice the memory space occupied.

REFERENCES

http://www.answers.com/Q/What_is_multi_pass_assembler
http://albertstu16.blogspot.in/2013/04/what-is-multi-pass-assembler.html
https://sites.google.com/site/assignmentssolved/mca/semester3/mc0073/30
https://www.quora.com/What-are-advantages-of-assembler-with-multiple-passes
https://books.google.co.in/books?id=IUVm4y-
XRecC&pg=PA103&lpg=PA103&dq=multi+pass+assembler&source=bl&ots=7B
ry8tSOl6&sig=7Uk1cnIWD7-
oTXr_Ad9_o1ABhfc&hl=en&sa=X&ved=0ahUKEwj9nIK8qIzRAhUMuI8KHbc
HDHA4ChDoAQguMAU#v=onepage&q=multi%20pass%20assembler&f=false
solomon.ipv6.club.tw/Course/SP.941/sp2-4.pdf
http://homepage.cs.uiowa.edu/~jones/syssoft/fall00/notes/04fwd.html
https://www.classle.net/#!/classle/book/system-software-and-assemblers-2-marks

You might also like