Assembler(First Pass Second Pass)
●
An assembler is a program that accepts a symbolic language program and
produces its binary machine language equivalent.
● The input symbolic program is called the source program and the
resulting binary program is called the object program.
● The assembler is a program that operates on character strings and
produces an equivalent binary interpretation
First Pass Assembler
●
●
●
●
●
●
●
●
During the first pass, it generates a table that correlates all user-defined
address symbols with their binary equivalent value· The binary translation is
done during the second pass.
To keep track of the location of instructions, the assembler uses a memory
word called a location counter (abbreviated LC).
The content of LC stores the value of the memory location assigned to the
instruction or operand presently being processed
The ORG pseudo instruction initializes the location counter to the value
of the first location.
Since instructions are stored in sequential locations, the content of LC is
incremented by 1 after processing each line of code
To avoid ambiguity in case ORG is missing, the assembler sets the location
counter to 0 initially.
LC is initially set to 0.
A line of symbolic code is analyzed to determine if it has a label (by the
presence of a comma).
●
●
●
●
●
If the line of code has no label, the assembler checks the symbol in the
instruction field
If it contains an ORG pseudo instruction, the assembler sets LC to the
number that follows ORG and goes back to process the next line.
If the line has an END pseudo instruction, the assembler terminates the first
pass and goes to the second pass.
If the line of code contains a label, it is stored in the address symbol table
together with its binary equivalent number specified by the content of LC
Nothing is stored in the table if no label is encountered.
LC is then incremented by 1 and a new line of code is processed
·
Second Pass Assembler
·
●
Machine instructions are translated during the second pass by means of
table-lookup procedures.
● A table-lookup procedure is a search of table entries to determine whether a
specific item matches one of the items stored in the table
● The assembler uses four tables. Any symbol that is encountered in the program
must be available as an entry in one of these tables; otherwise, the symbol
cannot be interpreted.
1.Pseudo instruction table
2. MRI table
3. Non-MRI tableasdf
4. Address symbol table
The entries of the pseudo instruction table are the four symbols ORG,
END, DEC, and HEX.
●
●
●
●
●
The non-MRI table contains the symbols for the 18 register-reference and input-output
The MRI table contains the seven symbols of the memory-reference instructions
and their 3-bit operation code equivalent
The address symbol table is generated during the first pass of the assembly
process.
The assembler searches these tables to find the symbol that it is currently
processing in order to determine its binary value.
LC is initially set to 0.
● Lines of code are then analyzed one at a time.
● Labels are neglected during the second pass, so the assembler goes
immediately to the instruction field and proceeds to check the first symbol
encountered.
● It first checks the pseudo instruction table.
● A match with ORG sends the assembler to a subroutine that sets LC to an initial
value.
● A match with END terminates the translation process. An operand pseudo
instruction causes a conversion of the operand into binary.
● This operand is placed in the memory location specified by the content of LC.
●
The location counter is then incremented by 1 and the assembler continues to
analyze the next line of code.
● If the symbol encountered is not a pseudo instruction, the assembler refers to
the MRI table.
● If the symbol is not found in this table, the assembler refers to the non-MRI table.
● A symbol found in the non-MRI table corresponds to a register reference or inputoutput instruction.
● The assembler stores the 16-bit instruction code into the memory word specified
by LC.
●
●
The location counter is incremented and a new line analyzed.
When a symbol is found in the MRI table, the assembler extracts its equivalent
3-bit code and inserts it m bits 2 through 4 of a word.
● A memory reference instruction is specified by two or three symbols.
● The second symbol is a symbolic address and the third, which may or may not
be present, is the letter I.
● The symbolic address is converted to binary by searching the address symbol
table.
●
The first bit of the instruction is set to 0 or 1, depending on whether the letter I
is absent or present.
● The three parts of the binary instruction code are assembled and then stored in
the memory location specified by the content of LC.
●
·
·
·
·
·
·
·.
· .
Name:
Description:
…