Sie sind auf Seite 1von 9

Assembler

The Assembler is used to translate the program written in Assembly language into machine code.
The source program is a input of assembler that contains assembly language instructions. The
output generated by assembler is the object code or machine code understandable by the
computer.
Since each assembly language is designed for a specific processor, assembling a program is
performed using a simple one-to-one mapping from assembly code to machine code.

 Assembler is the language translator that accepts inputs as assembly language (ALP) and
obtains its machine equivalent code (Object code) along with the information required by
the loader.
 Assembly language program is a low level language.
 The execution of statements can be done line by line.

Types of ALP

 Absolute ALP

The address specified for the execution is fixed .we cannot change the address .the
allocation is done by the programmer.

 Relative ALP

The address specified for the execution can be changed the allocation is done by the
loader.

Consider the below example:


Pseudo Opcode Table (POT)

 POT is the fixed length table.


 In pass 1, using Pseudo Opcode, POT is consulted for processing some pseudo opcode
like DS, DC, START, END, etc.
 In pass 2 using Pseudo Opcode, POT is consulted for processing some pseudo opcode
like DS,DC,USING DROP.

Pseudo Opcode Address of routine to process pseudo opcode


START -
USING -
DROP -
EQU -
DC -
DS -

START-

 It is used to specify the starting execution of a program.

USING –
 It specifies the base table register that is been used.

DROP –

 It is used to remove the register used in the base table.

EQU-

 It is used for making program more readable. Whenever symbol define with EQU
statement no memory would be allocated only an entry would make in symbol table.

Declare Constant (DC) -

 It is used to declare or define the values.

Declare Storage (DS) -

 It is used to store the value at specified address.

Machine Opcode Table (MOT)

 MOT is a fixed length table i.e. we make no entry in either of the passes.
 It is used to accept the instructions and convert/gives its binary opcode.
 In pass 1, using mnemonic Opcode, MOT is consulted to update location Counter (LC).
 In pass 2, using mnemonic opcode ,MOT is consulted to obtain

1) Binary opcode (to generate the instruction).

2) Instruction length (to update the instruction).

3) Instruction Format (to assemble the instruction).

M/C Instruction Binary Opcode Length Instruction Format


L 4 -
A 4 -
ST 4 -

 L 1, data

Load the data into register.

 A 1, data

Add the data into register.


 ST 1, temp

Store the content of register to temp (constant).

Instruction:

 RR
o The first operand is register and second operator is also register

Opcode Operand1 Operand2

 RX
o The first operand is register and second operator is an address.
o The address is generated by considering Base + index + displacement.

Opcode Operand1 Operand2

Address = (Base + index + displacement)

Symbol Table (ST)

 Symbol table is used for keeping the track of symbol that are defined in the program.
 It is used to give a location for a symbol specified.
 Symbol is said to be defined it appears in a label field.
 In pass 1, whenever a symbol is defined and for entry is made in symbol table.
 In pass2, symbol table is used for generating address of a symbol.

Symbol Vale Length Relative/Absolute


PQR 00 01 R
FIVE 16 04 R
FOUR 20 04 R
BASE 10 01 A
TEMP 24 04 R

Literal Table (LT)


 Literal table is used for keeping track of literals that are encountered in the programs.
 We directly specify the value, literal is used to give a location for the value.
 Literals are always encountered in the operand field of an instruction.
 In pass 1, whenever a Literal is defined and for entry is made in Literal table.
 In pass2, Literal table is used for generating address of a Literal.

Literal Vale Length Relative /Absolute


= F ‘5’ 28 04 R

References link :
http://www.ques10.com/p/8887/with-reference-to-assembler-explain-following-ta-2/

Pass 1:
BEGIN {construction of symbol table}
Skip over initial comment lines Process the
START statement, if present, setting Locctr and
ENDval to the operand’s value Loop through the
source lines until the END statement is reached
or the source file runs out
BEGIN
Skip over source lines that are comment lines
Extract Label, Opcode, & Operand parts
IF there is a Label
add it to the symbol table if it is not
already there (otherwise it’s an error)
Increment Locctr:
1. If Opcode is a storage directive, for
BYTE, RESB, or RESW, Operand determines
increment; for WORD it is 3
2. If Opcode is an instruction, the increment
is 1,2,3, or 4 as per Opcode bits
3. Increment = 0 for assembler directives
END {of loop}
If present, process END statement, and reset
ENDval
to the END statement’s operand value, if present
END {of Pass 1}
Pass 2:
BEGIN {generation of object module}
Write assembler report headings & any leading
comment lines (Note: as each source line is
processed, it is written to the assembler
report)
Process the START statement, if present, setting
Locctr to the operand’s value (default is 0)
Initialize the object module:
1. Locctr value is initial load point
2. ENDval from Pass 1 is tentative “execute
next”
Loop through the source lines until the END
statement is reached or source runs out
BEGIN
Skip over any comment lines (but write them
to the assembler report)
Extract Opcode, & Operand, increment Locctr,
then
if Opcode is
1. RESW or RESB, start a new module:
a. ! delimiter to end prior module
b. loader address replaces ENDval in
prior module as “execute next”
c. Locctr value is next load point
d. ENDval from Pass 1 as this module’s
a tentative “execute next”
2. WORD or BYTE, Operand gives the storage
value(s) to write to the object module
3. an assembler directive, process as spec’d
4. an instruction, build the object version
utilizing nixbpe bits, Locctr, and
Operand value from the symbol table
END {of loop}
Append the ! delimiter to end the final module
Output the object module(s) as the object code
file
if no errors were encountered in Pass 1 or 2
END {of Pass 2}