Module 2 - Assemblers & Macro Processor
Module 2 - Assemblers & Macro Processor
Module 2 - Assemblers & Macro Processor
Assembler : An assembler is a program that accepts as input an assembly language program &
produces its machine language equivalent along with information for the loader.
• Functions of Assembler:
1. Imperative statement:
Understood by m/c & executed by m/c.
e.g. All the instructions.
1. Declarative statements:
DC statement: Declare Constant
Label Opcode Operand
FOUR DC F ‘4’
1) Registers:-
2) Memory:-
Unit Of Memory Bytes Bits
Byte 1 8
-Basic unit Bytes.
Half Word 2 16
Full Word 4 32
Double Word 8 64
Instruction Formats:
a) RR Format:-
In this format the first & second operands present in the registers.
Format:
Opcode R1 (OP1) R2 (OP2)
0 7 8 11 12 15
e.g AR 3,4
3) RX format:
-In this format first operand is in the register & second operand is external (
present in the memory location).
-The address of second operand is given by-
C (B2) + C(X2) + D2
Contents of Base Reg. + Contents of Index Reg. + Displacement
Format:
Opcode R1 X1 B2 D2
0 7 8 11 12 15 16 19 20 31
e.g A 1, 90(2,15)
i.e. C(15) + C(2) +90
Assembler Directives :
USING & DROP
• USING: It is an assembler directive statement which indicates that the given register is available to be used as base
register along with its value.
Format:
• DROP statement: It is a assembler directive statement which indicate that the given register is unavailable to be used
as base register.
Format:
• The rules of ALP state that the symbol should be defined somewhere in
the program. So that there might be a case in which a reference is made to
a symbol prior to its definition. Such a reference is called forward
reference.
b) What is FRP?
•The function of the assembler is to replace each symbol by its m/c address
& if we refer to that symbol before it is defined , its address is not known by
the assembler. Such a problem is called FRP.
Example of FRP
- Forward reference problem (For IBM 360) is solved by
making two passes over the assembly code.
Pass1:-
Purpose- Define Symbols & Literals.
1) Keep track of LC.
2) Determine length of m/c instructions.
Pass2:
Purpose- Generate Object Program.
1) Lookup values of symbols.
2) Generate instructions.
3) Generate data.
4) Process some Pseudo-ops e.g. USING, DROP.
Format of Databases: 1. MOT
MOT is a fixed length table i.e. the contents of these tables are not altered during the
assembly process.
= F ‘5’ 28 04 R
-
- LT is used to keep a track on the Literals encountered in the program.
- In pass1- whenever the literals are encountered an entry is made in the LT.
- In pass2- Literal table is used to generate the address of the literal.
Base Table (BT):
1 ‘N’ -
2 ‘N’ -
. -
.
.
15 ‘N’ 00
- Code availability-
- Y- Register specified in USING pseudo-opcode.
- N--Register never specified in USING pseudo-opcode.
- BT is used to keep a track on the Register availability.
- In pass1- BT is not used.
- In pass2- In pass2, BT is consulted to find which register can be used as base registers
along with their contents.
Location Counter (LC)
- LC is used to assign addresses to each instruction & address to the symbol defined in the
program.
2) As in pass 1, the operation code field is examined to determine if it is a pseudo-op; if it is not, the table of
machine op-codes (MOT) is searched to find a-match for the card's op-code field. The matching MOT entry
specifies the length, binary op-code, and the format type of the instruction. The operand fields of the different
instruction format types require somewhat different processing.
3) For the RR-format instructions, each of the two register specification fields is evaluated. This evaluation
may be very simple, as in:
AR 2, 3.
4) For RX-·format instructions, the register and index fields are evaluated and processed in the same way as
the register specifications for RR-format instructions.
6) The USING and DROP pseudo-ops, which were largely ignored in pass 1, require additional processing in
pass 2. The operand fields of the pseudo-ops are evaluated; then the corresponding Base Table entry is either
marked as available, if USING, or unavailable, if DROP. The base table is used extensively in pass 2 to
compute the base and displacement fields for machine instructions with storage operands.
7) The DS and DC pseudo-ops are processed essentially as in pass 1. In pass 2, however, actual code must be
generated for the DC pseudo-op.
8) The END pseudo-op indicates the end of the source program and terminates the assembly. Various
"housekeeping" tasks must now be performed. For example, code must be generated for any literals remaining
in the Literal Table.
PASS 2
FLOWCHART
FAQ
Macro-Processor
• Macros: Single line abbreviation for group of instructions
• Macro Definition:
The template to be followed for defining a MACRO is as follows:
Macro Name
Macro Body
A 1, DATA Add contents of DATA to register 1 The above requirement can be achieved by using macro facility as follows.
Source Expanded source
A 2, DATA Add contents of DATA to register 2
MACRO
A 3, DATA Add contents of DATA to register 3
INCR
.
A 1,DATA
.
A 2,DATA
.
A 3,DATA
MEND
A 1, DATA Add contents of DATA to register 1
.
A 2, DATA Add contents of DATA to register 2
.
A 3,DATA Add contents of DATA to register 3 .
A 1, DATA
. INCR A 2, DATA
Source
Macro Expanded Compiler or obj
Code
(with macro)
Processor Code Assembler
Features of Macroprocessor
.
.
.
DATA DC F '5'
DATA DC F '10’
- In this case the instruction sequences are very similar but not identical. The first
sequence performs an operation using DATAl as operand; the second, using DATA2.
Example 1
Example 2: Supply more than one argument in
a macro call.
. .
. A 1, DATA3
.
INCR DATA3, DATA2, DATA1 A 2, DATA2
. . . A 3, DATA1
DATA DC F '5'
DATA DC F '10’ .
DATA DC F '15’
DATA1 DC F'5'
DATA2 DC F’10’
DATA DC F’15’
2. Conditional Macro Expansion:
AIF is a conditional branch pseudo-o ; it performs an arithmetic test and branches only if the tested condition is
true.
AGO is an unconditional branch pseudo-op or 'go to' statement.
Example 4:
In this example, the operands, labels, and the number of instructions generated change in each
sequence. This program could be written as follows: DATAl DC F'5'
. DATA2 DC F'10'
. DATA3 DC F'15'
.
3. Macro Calls Within Macros
Macro definition within macros
Design of Two Pass Macro processor
• The macro processor algorithm will two passes
over the input text, searching for the macro
definition & then for macro calls Argument List Array:
1. The input macro source deck 1. The copy of the input macro source deck
2. The output macro source deck copy for use by pass 2 2. The output expanded source deck to be used as
3. The Macro Definition Table (MDT), used to store the input to the assembler
body of the macro definitions 3. The Macro Definition Table (MDT), created by
4. The Macro Name Table (MNT), used to store the pass 1
names of defined macros
4. The Macro Name Table (MNT), created by pass 1
5. The Macro Definition Table Counter (MDTC), used
5. The Macro Definition Table Pointer (MDTP),
to indicate the next available entry in the MDT
used to indicate the next line of text to be used
6. The Macro Name Table Counter (MNTC), used to during macro expansion
indicate the next available entry in the MNT
6. The Argument List Array (ALA), used to
7. The Argument List Array (ALA), used to substitute
substitute macro call arguments for the index
index markers for dummy arguments before storing a
markers in the stored macro definition
macro definition
Algorithm of Pass1 & Pass2
Macro processor:
PASS I-MACRO DEFINITION: PASS2-MACRO CALLS AND EXPANSION:
The algorithm for pass 2 tests the operation mnemonic of each
The algorithm for passl tests each input line. input line to see if it is a name in the MNT. When a call is
found:-
If-it is a MACRO pseudo-op:
1. The entire macro definition that follows is 1)The macro processor sets a pointer, the Macro Definition
saved in the next available locations in the Table Pointer (MDTP) , to the corresponding macro definition
Macro Definition Table (MDT).
stored in the MDT. The initial value of the MDTP is obtained
from the "MDT index" field of the MNT entry.
2. The first line of the definition is the macro
name line. The name is entered into the Macro
Name Table (MNT), along with a pointer to 2)The macro expander prepares the Argument List
the first location of the MDT entry of the Array(ALA) consisting of a table of dummy argument indices
definition. and corresponding arguments to the call.