ASSembler (2)
ASSembler (2)
ASSembler (2)
2) Symbolic Operands:
- Symbolic names can be associated with data or instructions & can be used
in assembly statement as operand.
3) Data Declarations:
• Statement Format:
An assembly language statement has the following format:
Where
AREA => refers to the memory word with which the name AREA is associated.
AREA+5 => refers to the mem ory word 5 word away from the word with the name
AREA.
AREA(4) => operand addren is obtained by adding the contents of index register &
to the addren of AREA.
AREA+5(4) => combination of previous two.
Opcode mnemonic
03 MULT
07 BC Branch on condition
10 ………… ………………….
It transfer control to memory word with the addren <memory addren> if the current
value of condition code matches <condition code spec>.
- The opcode, register operand & memory operand occupy 2, 1 & 3 digits.
- Sign is not part of instruction.
1) Imperative Statements
2) Declarative Statements
3) Assembler Directives
1) Imperative statements:
- It indicates an action to be performed during the execution of the assembled
programs.
- Each imperative statement typically translates in to one machine instruction.
2) Declarative statements:
Syntax is
[Label] DS <constant>
[Label] DC ‘<value>’
The DS (short for declare storage) statement reserves area of memory &
associates name with them.
Consider the following DS statements.
A DS 1
G DS 200
The DC ( short for declare constant ) statement construct memory words containing
constant.
- It associates the name ONE with a memory word containing the value ‘1’.
- Constant can be a form decimal, binary, hexadecimal etc.
3) Assembler Directives:
- Assembler directives instruct the assembler to perform certain actions during
the assembly of a program.
Indicates that first word of the target program generated by the assembler should
be placed in the memory word with addren <constant>
This directive indicates end of source program optional part indicates addren of
instruction where execution of pgm should begin.
For this, we need to consider two data structure during the synthesis phase:
1) Symbol table
2) Mnemonics table
1)Symbol table:
- It has two entries name & addren.
- It is built by analysis phase.
2)Mnemonics table:
- It has two primary fields mnemonic & opcode
- The synthesis phases uses these table to obtain the machine addren with which
a name is associated & machine opcode corresponding to a mnemonic
respectively.
- Searching is done by symbol name & mnemonic as keys.
Analysis Phase:
Data access
Analysis Phase:
Synthesis Phase:
It can handle forward references easily as first pass will do LC processing &
creates a symbol table and also constructs an IR of SP.
The second pass uses symbol table, IR & gives TP, simply we can say
synthesis is performed by second pass as shown in fig 2.3.
Data access
- The need of inserting the second operands addren at later stage can be
indicated by adding an entry to the Table Incomplete Instruction. (TII).
- By the time END statement is processed, symbol table would contain all the
addrens & TII would contain info of all forward references.
PassI.
PassII.
Pass I perform analysis of the SP & synthesis of the IR while Pass II processes
the IR to synthesize the target program.
ORIGIN
Where,
LTORG:-
Let us take an example to understand all the data structures. (example 2.4)
1 START 200
7 ……
12 BC ANY, NEXT 210) +07 6 214
13 LTORG
14 ……
18 ORIGIN LOOP +2
20 ORIGIN LAST +1
21 A DS 1 217)
23 B DS 1 218)
24 END
1) Addren.
2) Representation of mnemonic opcode.
3) Representation of operands.
Fig. An IC unit
Mnemonic Field:-
DC 01
DS 02 START 01
END 02
ORIGIN 03
Thus (AD, 01) stands for START.
Variant- I
Where,
LTORG (AD,01)
……….. ………….
Varient – II
STOP (IS,00)
LTORG (AD,05)
…….. ………
Algorithm.
TABLES:
- A single pass assembler for intel 8088 shares some problems with other single
pass assemblers.
Eg problems in assembling forward references in error reporting.
- We know that if at all there is forward reference, its entry is made in TII.
- When symbol’s def is encountered, this entry would be analysed to complete
the instruction. However use of symbolic name as a definition in branch
instruction gives rise to a peculiar problem.
- Some generic branch opcodes like JMP in 8088 assembly language can give
rise to instruction of different formats & different length depending on
whether the jump is near or far.
- However this would not be known until sometime later in the assembly
process. This problem is solved by assembling such unless a programmer
indicates a short displacement.
Eg. JMP SHORT LOOP.
Design of Assembler:
1) Forward reference:
- Infromation concerning forward references to a symbol is organized in the
form of a linked list.
- Thus, the forward reference table (FRT) contains a set of linked lists.
- The FRT pointer field of a SYMTAB entry points to the head of this list.
- For efficiency reason new entries are addren at the beginning of the list.
2)Cross references:
- The assembler uses a cross-reference table (CRT) to collect the information
concerning referencing to all symbols in the program.
- Each SYMTAB entry points to the head & tail of the linked list in the CRT.
- Here, new entries are added at the end of the list.