0% found this document useful (0 votes)
7 views

MODULE2_Features, Statements and Forwrd Reference Prob

The document provides an overview of assemblers, detailing the elements of assembly language programming, the structure of assemblers, and the design of two-pass and single-pass assemblers for the X86 processor. It explains the types of assembly language statements, the phases of an assembler, and the data structures used, including various tables like the Mnemonic Opcode Table and Symbol Table. Additionally, it discusses the forward reference problem and how it is addressed through the two-pass assembly process.

Uploaded by

munchingsilver7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

MODULE2_Features, Statements and Forwrd Reference Prob

The document provides an overview of assemblers, detailing the elements of assembly language programming, the structure of assemblers, and the design of two-pass and single-pass assemblers for the X86 processor. It explains the types of assembly language statements, the phases of an assembler, and the data structures used, including various tables like the Mnemonic Opcode Table and Symbol Table. Additionally, it discusses the forward reference problem and how it is addressed through the two-pass assembly process.

Uploaded by

munchingsilver7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

MODULE 2

Assemblers
https://www.slideshare.net/slideshow/10design-of-two-pass-assembler-in-system-softwarepdf/266918869#8

Prepared By: Vandana V.


Contents

• Elements of Assembly Language programming,

• Assembly scheme,

• pass structure of assembler,

• Assembler Design: Two pass assembler Design and single pass Assembler
Design for X86 processor,

• Data structures used.


Elements Of Assembly Language Programming

• Assembler.
• Assembly Language.
• Types of Assembly language statements.
Assembler.
• An assembler translates assembly language into machine language
Assembly Language
• Assembly language is a low-level language that helps to communicate
directly with computer hardware.
• Assembly language statements are entered one statement per line.
• Each statement follows the following format −

• [label] mnemonic [operands] [;comment]


• Mnemonic instructions: Assembly language uses mnemonics to represent
machine code instructions. Ex. ADD, SUB
• Mnemonics are symbolic names that are easier to remember than machine
language patterns.

• Symbolic Operands: Symbolic names associated with data or instruction. It is


used as Operands in assembly language. Ex. ADD R1,R2

• Data Declaration: Data can be declared using variety of notations including


hexadecimal notatation.
• Example: L1 MOVE AREG ,03
Register operand Memory operand
in symbolic form in symbolic form

• [label] mnemonic [operands] [;Data Declaration]


STATEMENTS IN ALP
1. Imperative statements:
These are the statements understood and executed by machine.
Ex. Instructions
2. Declarative Statements:

These statements are used for declaration purpose.


i. DC Statement :(Declare /Define Constant)
Ex.
D1 DC F ‘4’
D2 DC H ‘5’
• DS Statement : (Define Storage) for reserving memory for
variables.
• S1 DS ‘10’ B label Statement 10bytes to B
• S2 DS ‘8’ D

3. Assembler Directive Statements:


Theses are the statements that direct the assembler to take necessary
actions.
i) START statement;
PG1 START Register
PG2 START 0
PG3 START 4000 Absolute
ii) END statement;
4. USING statement
It indicates which register to be used as base register.
5. DROP Statement
Used to drop a base register that has been allocated by USING
statement.
Some Examples
INC COUNT ; Increment the memory variable

COUNT MOV TOTAL, 48 ; Transfer the value 48 in the ; memory variable

TOTAL

ADD AH, BH ; Add the content of the ; BH register into the AH register

AND MASK1, 128 ; Perform AND operation on the ; variable MASK1 and 128

ADD MARKS, 10 ; Add 10 to the variable MARKS

MOV AL, 10 ; Transfer the value 10 to the AL register


TYPES OF ASSEMBLY LANGUAGE PROGRAM

1. Absolute / Non Relocatable programs. (Fixed)


A non-relocatable program is a program that can only be executed in
the memory area where it was coded or translated.

2. Relocatable Programs :(Non-Fixed)


A relocatable program is a computer program that can be executed in
different parts of memory at different times.
DESIGN OF AN ASSEMBLER for IBM-360 PROCESSOR
1. Registers:
There are 16 General purpose registers (0-15)
4 Floating point register.
1 Program status word.
2. Memory :
Various units of memory is available as follows:
Units Bytes Bits

B Bytes 1 8
H Half Word 2 16
F Full word 4 32
D Double word 8 64
Instruction Format
1. R-R Format
First operand is in the register and second operand in register.
OPCODE R1 R2

1. R-X Format
First operand is in the register and second operand in
memory.
OPCODE R1 X2 B2 D2

First operand Second operand


ASSEMBLY SCHEME /PHASES OF An ASSEMBLER
ASSEMBLY SCHEME /PHASES OF An ASSEMBLER

• The Assembler operates in two main phases: Analysis Phase (Pass 1)


and Synthesis Phase (Pass 2).

• The Analysis Phase validates


• the syntax of the code,
• checks for errors, and
• creates a symbol table.
The Analysis Phase is responsible
• Analysis phase:

• Separate contents of the label, mnemonic opcode and operand fields of a statement.

• If a symbol is present in the label field, enter the pair (symbol, <LC>) in a new
entry of the symbol table.

• Check validity of the mnemonic opcode through a look-up in the Mnemonics table.

• Perform LC processing, i.e., update the address contained in the location counter by
considering the opcode and operands of the statement.
Store value or address assigned to the label

203
• 3. Mnemonic Opcode Table (MOT) or OPTAB
Mnemonic Binary Variable/Operand Instruction
Opcode Opcode Length(Bytes)
MOVER 04 3 2
MOVEM 05 x 1
MOVER 04 2 2
ASSEMBLY SCHEME /PHASES OF An ASSEMBLER
Synthesis phase:

• Obtain the machine opcode corresponding to the mnemonic from the


Mnemonics table.

• Obtain the address of each memory operand from the Symbol table.

• Synthesize a machine instruction or the correct representation of a constant,


as the case may be.
• The Synthesis Phase converts

• the assembly language instructions into machine code, using the


information from the Analysis Phase.

• These two phases work together to produce the final machine code
that can be executed by the computer.

• The combination of these two phases makes the Assembler an


essential tool for transforming assembly language into machine code,
ensuring high-quality and error-free software.

• https://www.youtube.com/watch?v=3gEyq9wDGeg
FORWARD REFERENCE PROBLEM
MACHINE OPCODE TABLE (MOT) PSEUDO OPCODE TABLE (POT)
MNEMONIC BINARY INSTRUCTIO INSTR. PSEUDO ADDRESS OF THE ROUTINE TO
OPCODE OPCODE N LENGTH FORMAT
OPCODE PROCESS THE PSEUDO OPCODE
L
DC
A
DS
ST
START
LITERAL TABLE (LT)
END
LITERAL LOC LENGTH R/A
VALUE
BASE TABLE(BT)
REGISTER CONTENTS
AVAILABILITY AVAILABLE
SYMBOL TABLE (ST) 0 -N
SYMBOL LOC LENGTH R/A 1-N
VALUE
..
15-N
LC LITERAL TABLE (LT) PSEUDO OPCODE TABLE (POT)
0 LITERAL LOC LENGTH R/A PSEUDO ADDRESS OF THE
VALUE OPCODE ROUTINE TO PROCESS
0 THE PSEUDO OPCODE
0 DC --
DS --
START --
MACHINE OPCODE TABLE (MOT)
END --
MNEMONI BINARY INSTRUCTI INSTR.
C OPCODE OPCODE ON FORMAT USING --
LENGTH
BASE TABLE(BT)
L 08 4 RX
REGISTER CONTENTS
A 01 4 RX
AVAILABILITY AVAILABLE
SYMBOL TABLE (ST)
0 -N
SYMBOL LOC LENGTH R/A ST 12 2 RX
1-N
VALUE
..
PG1 00 00 R
15-N /Y 00
LC
0 Binary Op R1 Base index Displacement
0
0
08 1 15 0 ??

If brackets are present then index is present .


.if no brackets then no index

Value of symbol in symbol table.


FORWARD REFERENCE PROBLEM
• The rules of assembly language program states that the symbol can be
defined anywhere in the program.
• Hence there may be some pases in which the reference is made to the
symbol prior to its definition and such a reference is called Forward
Reference.
• Due to forward reference assembler can not find the address of the
symbol and hence not able to assemble the instructions & such a problem
is called Forward Reference Problem.

• To solve this problem assembler will make two passes over the input
Program.

• The purpose of pass1 is to define the symbols & the literals encountered
in the program.

• The purpose of pass2 is to assemble the instructions & assemble the data.
PSEUDO OPCODE TABLE (POT)
LC LC
PSEUDO OPCODE ADDRESS OF THE ROUTINE
TO PROCESS THE PSEUDO
OPCODE
DC --
D(I,B) DS --
START --
END --
USING --
BASE TABLE(BT)
REGISTER CONTENTS AVAILABLE
AVAILABILITY
0 -N

PASS 1 PASS 2 1-N

SYMBOL TABLE (ST) MACHINE OPCODE TABLE (MOT) ..

SYMBOL LOC LENGTH R/A MNEMONIC BINARY INSTRUCTION INSTR. 15-N


OPCODE OPCODE LENGTH FORMAT
VALUE
LITERAL TABLE (LT)
L 08 4 RX
LITERAL VALUE LENGTH R/A
A 01 4 RX

ST 12 2 RX
LC LC LITERAL TABLE (LT)
LITERAL VALUE LENGTH R/A
0 0
0 0
0 L 1 ___ 0 L 1 12(0,15) D(I,B)
4 A 1 ____ 4 A 1 16(0,15) SYMBOL TABLE (ST)
8 ST 1 ____ 8 ST 1 20(0,15) SYMBOL LOC LENGTH R/A
12 12 0100 VALUE
16 16 0101 PG1 00 00 R
20 20 ___ FOUR 12 4 R
24 24 FIVE 16 4 R
PASS 2 TEMPOPCODE20
PSEUDO TABLE (POT)4 R
PASS 1
MACHINE OPCODE TABLE (MOT) BASE TABLE(BT) PSEUDO OPCODE ADDRESS OF THE ROUTINE
MNEMONI BINARY INSTRUCTI INSTR. TO PROCESS THE PSEUDO
REGISTER CONTENTS
C OPCODE OPCODE ON FORMAT OPCODE
AVAILABILITY AVAILABLE
LENGTH DC --
0 -N
L 08 4 RX DS --
1-N
A 01 4 RX START --
.. END --

ST 12 4 RX 15-N /Y 00 USING --
DATA STRUCTURES USED BY ASSEMBLER / FORMAT OF DATABASE

• These are the tables which are maintained by 2 pass assembler to


process the instructions.
1. Mnemonic Opcode Table/ Machine Opcode Table (MOT)

2. Pseudo Opcode Table (POT)

3. Symbol Table

4. Literal Table

5. Base Table
MACHINE OPCODE TABLE (MOT) 1. MOT is a fixed length table i.e assembler will make no entries in either of
MNEMON BINARY INSTRUCTI INSTR.
IC OPCODE ON FORMAT passes.
OPCODE LENGTH
2. In pass 1 MOT is consulted to obtain instruction length which will be used
L 08 4 RX
A 01 4 RX to update LC(Location Counter).
3. In Pass 2 MOT is consulted to obtain:
ST 12 4 RX
1. Binary Opcode→ To replace mnemonic Opcode.

PSEUDO OPCODE TABLE (POT)


2. Instruction Length→ to update LC
PSEUDO OPCODE ADDRESS OF THE ROUTINE 3. Instruction Format→ to assemble the instruction.
TO PROCESS THE PSEUDO
OPCODE

DC -- 1. POT is also fixed length table.


DS -- 2. In Pass 1 POT is consulted for processing of some pseudo-opcodes like
START --
END --
START, DC,DS.
USING -- 3. In Pass 2 POT is consulted for the processing of some pseudo-opcodes like
USING, DROP, DC etc.
SYMBOL TABLE (ST) 1. It is used to keep track of the symbols that are defined in the
SYMB LOC LENGT R/A program.(Symbol is defined whenever it appears in the label
OL VALUE H
field).
2. In Pass1 whenever a symbol is defined, entry for that symbol is
made in the symbol table.
3. In Pass2, Symbol table is used for generating address of the
symbol.
LITERAL TABLE (LT)
LITERAL VALUE LENGTH R/A
1. It is used to keep track of the literals that are encountered in the
program. (Literal is encountered whenever it appears in the
operand field).
2. In pass1 whenever a literal is encountered , entry for that literal
is made in the literal table.
3. In Pass2, literal table is used for generating address of the
literals.
BASE TABLE(BT)
REGISTER CONTENTS
1. It is used for keeping track on the base register information.
AVAILABILITY AVAILABLE
0 -N
2. In Pass1 BT is not required.
1-N 3. In Pass2 BT is required for processing of USING and DROP
..
15-N
statement.

You might also like