SPCC Module2
SPCC Module2
17/01/2025 1
Assembler
An Assembler can be defined as a program that translates an assembly language program into a
machine language program.
The assembler evaluates the mnemonics (symbols) in the operation field and finds the value of
symbols and literals to produce machine code.
Types of Assembler
Single-Pass Assembler: If an assembler does all this work in one scan then it is called a
single-pass assembler.
Multiple-Pass Assembler: If it does it in multiple scans then called a multiple-pass
assembler.
17/01/2025 2
Elements of Assembly Language programming
An assembly language is a machine dependent, low level
programming language.
it is specific to certain computer system.
It provide 3 basic features which simplify programming
Mnemonic Operation Codes
Symbolic operands
Data declaration
17/01/2025 3
Mnemonic operation codes: eliminates the need to memorize
numeric operation codes.
Symbolic operands: Symbolic names can be associated with
data or instructions. Symbolic names can be used as operands in
assembly statements
Data declarations: Data can be declared in a variety of
notations, including the decimal notation
17/01/2025 4
Simple Assembly scheme
<operand specification> has the following syntax:
<symbolic name> [± <displacement> ] [(<index register>)]
17/01/2025 5
Some possible operand forms are as follows:
The operand AREA refers to the memory word with which the name AREA is associated.
The operand AREA+5 refers to the memory word that is 5 words away from the word
with
the name AREA. Here '5' is the displacement or offset from AREA.
The operand AREA(4) implies indexing the operand AREA with index register 4—that is,
the
operand address is obtained by adding the contents of index register 4 to the address of
AREA.
The operand AREA+5 (4) is a combination of the previous two specifications.
17/01/2025 6
Types of Assembly Statements:
1. Imperative statement
An imperative statement indicates an action to be performed during the execution of the
assembled statement.
Each imperative statement typically translates into one machine instruction.
These are executable statements.
Some example of imperative statement are given below
MOVER BREG,X
STOP
READ X
PRINT Y
ADD AREG,Z
17/01/2025 7
Types of Assembly Statements:
2. Declaration statement
Declaration statements are for reserving memory for variables.
The syntax of declaration statement is as follow:
[Label] DS <constant>
*Label+ DC ‘<value>’
DS: stands for Declare storage, DC: stands for Declare constant.
The DS statement reserves area of memory and associates name with them.
A DS 10
Above statement reserves 10 word of memory for variable A.
The DC statement constructs memory words containing constants.
ONE DC ‘1’
17/01/2025 8
Types of Assembly Statements:
Above statement associates the name ONE with a memory word containing the value ‘1’
Any assembly program can use constant in two ways- as immediate operands, and as
literals.
Many machine support immediate operands in machine instruction. Ex: ADD AREG, 5
But hypothetical machine does not support immediate operands as a part of the machine
instruction. It can still handle literals.
A literal is an operand with the syntax =’<value>’. EX: ADD AREG,=’5’
It differs from constant because its location cannot be specified in assembly program.
17/01/2025 9
Types of Assembly Statements:
3. Assembler Directive
Assembler directives instruct the assembler to perform certain action during the assembly
program.
a) START
START <Constant>
This directive indicates that first word of machine should be placed in the memory word with
address <constant>.
START 500
First word of the target program is stored from memory location 500 onwards.
17/01/2025 10
Types of Assembly Statements:
b) END
This directive indicates end of the source program.
The operand indicates address of the instruction where the execution of
program should begin.
By default it is first instruction of the program.
END <operand 2>
Execution control should transfer to label given in operand field.
17/01/2025 11
Basic Functions of Assembler
Assembler translates mnemonics opcodes to machine language.
Convert symbolic operands to their machine addresses.
Build machine instructions in the proper format
Convert data constants into machine representation.
Error checking is provided.
Changes can be quickly and easily incorporated with a reassembly.
Variables are represented by symbolic names, not as memory locations.
Assembly language statements are written one per line. A machine code program thus
consists of a sequence of assembly language statements, where each statement contains a
mnemonics.
17/01/2025 12
Functions / Purpose of Assembler
An assembler must do the following
1. Generate instruction
a. Evaluate the mnemonics in the operation field to produce the machine code
b. Evaluate the subfield-fine the value of each symbol. Process literals and assign
addresses.
2. Process pseudo ops
17/01/2025 13
Pass structure of assembler
2. Process pseudo ops
a) Pass 1 (Define symbol and literals)
i. Determine length of machine instruction ( MOTGET)
ii. Keep track of location counter (LC)
iii. Remember value of symbol until pass 2 (STSTO)
iv. Process some pseudo ops(POTGET1)
v. Remember literal (LITSTO)
b) Pass 2 (Generate object Program)
i. Look up value of symbol (STGET)
ii. Generate instruction (MOTGET2)
iii. Generate data (for DS, DC and Literal)
iv. Process pseudo ops (POTGET2)
17/01/2025 14
SINGLE PASS ASSEMBLER
These assemblers are used when it is necessary or desirable to avoid a second pass
over the source program.
The main problem in designing the assembler using single pass was to resolve forward
references.
One-pass assemblers could produce object codes either in memory or to external
storage.
One-pass assemblers usually need to modify object code already generated.
Whether object code is stored in memory or external storage imposes different
considerations on assembler design.
17/01/2025 15
SINGLE PASS ASSEMBLER
Based on whether the object code is stored in memory or external storage, one-pass
assemblers can be classified into two types:
17/01/2025 16
1. Load-and-Go Assembler SINGLE PASS ASSEMBLER
1. Load-and-Go Assembler
Load-and-go assembler generates their object code in memory for immediate execution.
Since no object program is written out, no loader is needed.
It is useful in a system with frequent program development and testing.
Since the object program is produced in memory, the handling of forward references
becomes less difficult.
17/01/2025 17
Working of One pass assembler (Load and Go Assembler)
17/01/2025 18
Working of One pass assembler (Load and Go Assembler)
At the end of the program, reports the error if there are still SYMTAB entries
indicated undefined symbols(* indicates undefined).
When the END statement is encountered, search SYMTAB for the symbol named in
the END statement and jumps to this location to begin execution if there is no error.
17/01/2025 19
One Pass Assembler Generating Object Code for Later Execution
• In this type of one pass assembler, the generated object program is stored in
external storage (e.g.,files on disks).
• Random updates to operands target addresses are not permitted.
• For any symbol involved in forward references, once the target address of the
symbol is identified, additional text records must be generated to overwrite those
previously omitted target addresses.
• Records must be loaded in the same order as they appear in the object
program.
• Handling of forward references are jointly done by the assembler and the
linking loader.
17/01/2025 20
One Pass Assembler Generating Object Code for Later Execution
One pass assembler which generates object code operates in the following
fashion:
If the operand contains an undefined symbol, use 0 as the address and write
the Text
record to the object program.
Forward references are entered into lists as in the load-and-go assembler.
17/01/2025 21
One Pass Assembler Generating Object Code for Later Execution
17/01/2025 22
23
24
25
26
27
28
29
31
32
33
34
35
36
37
38
39
42
43
44