Introduction to System Software

Chapter 5
Assembler
• Assembler is program that change the source
program in assembly language to object
program in machine language.
• Characteristics & design depend on the source
program to be interpret & object program to be
produce.
• There are a few types of assembler:
– One path assembler
– Two paths assemble – to solve forward referencing
problem.
– Multiple paths assembler
the use of a symbol at one point in the text which is not
defined until some later point gives the wrong result.
5.1 The Purpose of Assembler
• To lighten programming task.
• Allow the use of symbol or mnemonics which are
more meaningful than a series of number to
represent instruction or data.
• Allocate storage space for instruction & data.
• Determine location for each instruction.
• Assemble also produce a program list which
include:
–
–
–
–
Copy to source instruction & instruction number.
Object code.
Error message if occur.
Symbol schedule for cross-referencing each symbol or name
found with the instruction number used as operand.
5.2 Two Paths of Assembler
• Path 1
– Allocate space for machine operation, data constant and
data storage.
– Symbol definition.
– Build symbol/cross-reference to store information about
all label & their addresses.
– Calculate the effective address for each label.
• Path 2
– Solve all symbol reference for each memory location.
– Change source instruction to machine/object code to fulfil
the allocated space.
– Issue program list and error message if available.
– Prepare constant for storage space & store in the storage.
5.3 Path 1 & Path 2 Objectives
1. Process Instruction
– If label space found identify value & place into
symbol table.
– Evaluate mnemonics in instruction to produce
equivalent machine code.
– Evaluate operand, fine its value & process the
value.
2. Process Assembler Directives
– When found, assemble will process the value.
Therefore, we can collect into 2 Path
path:
Path –
1:
2:
1.
2.
3.
4.
Identify machine language instruction length.
Find value for each label.
Create symbol table to remember all value in label.
Determine the relocatable instruction and set relocation
flag as needed.
1.
2.
Machine code
reference for each
instruction.
Value reference for
symbol &
implemented data.
5.4 Algorithm of Path 1 & Path 2
Path 2 flowchart : Generate object
code
5.5 Using Database & Data Structure
• Path 1
– Input: Source program
• Instruction table or operation code table
• Directive table or Pseudo code table
– Output: Symbol table
• Some assembles produce intermediary file that contain
source program with stack address as well as any error.
• Path 2
– Input: source program or intermediary file created from
Path 1
• Instruction table or operation code table
• Directive table or Pseudo code table
• Symbol table
– Output: Object Module (object file)
• Assembler listing file.
5.6 Relationship of Path 1 & Path 2
Instruction
table
Source
Program
Pass 1
Assembler
directive
table
Symbol
table
Location Counter
Pass 2
Object
Program
5.7 One Path Assembler
• Each label address must be remembered &
change when symbol table reject it.
• Less economical & less efficient if compare with
Two Path Assembler.
• One path assembler are normally “load-and-go
assembler”.
• This type of assembler cannot accommodate
relocation characteristics & also cannot be link to
other modules.