MODULE2_Features, Statements and Forwrd Reference Prob
MODULE2_Features, Statements and Forwrd Reference Prob
Assemblers
https://www.slideshare.net/slideshow/10design-of-two-pass-assembler-in-system-softwarepdf/266918869#8
• Assembly scheme,
• Assembler Design: Two pass assembler Design and single pass Assembler
Design for X86 processor,
• 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 −
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
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
• 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 address of each memory operand from the Symbol table.
• These two phases work together to produce the final machine code
that can be executed by the computer.
• 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 ??
• 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
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
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.