System Software Ch3
System Software Ch3
Syllabus
Elements of assembly language programming, Design afthe assembler, Assembler design criteria,
Types of assemblers, Two-pass assemblers, One-pass assemblers, Single pass assembler for intel
r86, Algorithm of single pass assembler, Multi-pass assemblers, Advanced assembly process,
Variants of assemblers design of two pass assembler.
Contents
3.1 Basic Assembler Functions Summer-19, Marks 3
3.2 Assembly Language Programming
3.3 Simply Assembly Scheme Winter-17, Marks 3
3.4 Pass Structure of Assemblers Summer-12, Winter-15,17,
Summer-18, Marks 7
•
(3 - 1)
System Sofware 3-2 Assemblers
The assembler is
responsible for Assembler Object Linker
Source Code
translating the assembly program
language program into
machine code. When Executable
code
the source language is
essentially a symbolic
representation for a Loader
numerical machine
language, the translator Fig. 3.1.1 Role of assembler
is called an assembler
and the source language is called an assembly language.
A pre assembly language is a language in which each statement produces exactly
one machine instruction. Fig. 3.1.1 shows the role of assembler.
Assembler functions
1. Translate mnemonic opcodes to machine language.
2. Convert symbolic operands to their machine addresses.
3. Build machine instructions in the proper format.
4. Convert data constants intò machine represenation.
5. Error checking is provided.
Label : It is an identifier and optional field. Labels are used extensively in programs
to reduce reliance upon programmers remembering where data or code is
located. The maximum length of label differs between assemblers. Some
accept upto 32 characters long, other only four characters. A label when
. Z)
declared is suffixed by a colon and begins with a valid character (A
For example
START LDAA # 24 H
Review Question
1. Define assembler. List out tasks perforned during different phase of assembler.
GTUESummer-19, Marks 3
1.
Mnemonic operation codes
2. Symbolic operands
3. Data declaration
Assembler function is translating mnemonic operation codes to their machine
language equivalents. Assigning machine addresses to symbolic labels.
Mnemonics are predefined assembly-language names for machine instruction,
pseudo-ops, directives and data allocation statements. Mnemonics are not
case-sensitive. It also enables the assembler to provide helpful diagnostics.
-
TECHNICAL PUBLICATIONS An up thrust for knowledge
System Sofware 3-4 Assemblers
Mnemonic are a set of readily memorized programming instruction that are later
translated into pure machine code by assembler.
An opcode is short for Operation Code'. An opcode is a single instruction that can
be executed by the CPU. In machine language it is a binary or hexadecimal
value
Such as 'B6' loaded into the instruction register,
Optional Mandatory
• Following is the simple assembly language :
ORIG x2000
LD R1. Four
ILD R2. NUM
AND R3, R3, #0 Clear R3,
The inner loop
AGAIN ADD R3. R3. R2
ADD R1, R1.
#-1 R1 keeps trackS of
BRp AGAIN the íteration
HALT
NUM BLKW1
Eout FILL x0006
END
Declaration statement: It focus on what the problem is and leave the solution
mechanism up to the language implementation. Within the declaratíve paradigm, most
notable are the functional languages uch as Lisp. Declarative languages are typically
quite abstract and hence can be harder to implemernt efficierntly.
Assembler Directive
Assembler directives instruçt the assembler to perform certain actions during the
assembly of a program. They can be used to declare variables, create storage space for
results, to declare constants., The following assembler directives are used in the
program :
1. START - Specify name and starting address for the program.
START< constant >
-
2. END Indicate the end of the source program and specify the first executable
instruction in the program.
END [< operand spec >]
3. BYTE - Generate character or hexadecimal constant, occupying as many bytes as
needed to represent the constant.
4. WORD - Generate one word integer constant.
-
TECHNICAL PUBLICATIONS An up thrust for knowledge
System Sofware 3-6 Assemblers
B.23 Disadvantages
1. Many instructions are required to achieve small tasks.
2. Source programs tend to be large and difficult to follow.
3. Programmer requires
knowledge of the processor architecture and instruction set.
4. Programs are machine
dependent, requires complete rewrites if the hardware is
changed.
TWO DC 215)
DATA DS 1
END
Memory allocation means the fixing the address of the assembly language
statement. Suppose we want to fix the memory address of M, then also fix the
address of remaining instructions. Location counter is a data structure used to
implement the memory allocation. Location Counter (LC) is always made to
contain the address of the 'next memory word in the target program. LC is
initialised to the constant specified in the START statement.
The detail procedure is given below.
1. In the analysis phase, it reads the label of the assembly statement. The label
and the contents of LC is enters as the new entry in the symbol table.
Source
program
Analysis
phase
Mnemonics Table
Symbol table
MnemonicsOpcode|Length Gontrol Transfer
Symbol Address
ataacces access
Synthesis
phase
ata
Target
program
Review Question
1. Explain the data structure of single pas assembler. GTU: Winter-17, Marks 3
Most of the assembler makes two passes over the source program. Pass one does
little more than scan the source program for label definitions and assign addresses.
The second pass performs most of the actual translation.
Assembler must process the assembler directives statements. These statements are
not translated into machine instructions. They provide instructions to the
assembler itself.
The assembler directives START specifies the. starting memory address for the
object program and END marks the end of the program.
At last, the assembler nmust write the generated object code onto some output
device. This object program will later be loaded into memory for executation.
Object program contains three types of records.
i) Header ii) Text ii) End
Header contains the program name, starting address and length.
Text record contains the translated instructions and data of the program, together
with an indication of the addresses where these are to be loaded.
End record marks the end of the object program and specifies the address in the
program where execution is to begin.
structure. COde
found in the symbol table.
Functions of the two passes of. a a
Data
access
simple assembler is as follows.
1. Assign addresses to all statements
Pass II
in the program.
2. Save the values assigned to all
labels for use in Pass 2.
Target program
3. Perform SOme processing of
assembler directives. Fig. 3.4.1 Two pass assembly
-
TECHNICAL PUBLICATIONS An up thrust for knowledge
System Software 3- 12 Assemblers
Pass 1:
start
read first input line
f OPCODE START then
begin
save nunber of OPERAND starting addresa
initialize location counter to starting address
write line to intermediate file
read next line
end (if START)
else
initialize location counter to zero
Whlle OPCODE END' do
begin
if line is comment line then
begin
if symbol in the LABEL field then
begin
search symbol table for LABEL
if found then
set emOI lag
else
TECHNICAL PUBLUCATIONS - An up
thrust for knowtedge
Soflwaro
Syslon 3- 13 Assemblers
START 101
READ N
MOVER BREG, ONE
MOVEM BREG, TERM
AGAIN
MULT BREG, TERM
MOVER: CREG, TERM
ADD CREG, ONE
MOVEM CREG, TERM
COMP CREG, N
BC LE, AGAIN
MOVEM BREG, AGAIN
PRINT RESULT
N STOP
RESULT DS
ONE DS 1
TERM DC 1
DS 1
END
Instuction opcode : STOP - 00, ADD - 01, MULT - 03, MOVER 04, MOVEM - 05,
-
Symbol Address
1
ONE 102
2 TERM 103
3 N 108
4 RESULT 110
:
i)
Intermediate code using Variant I representation
(IS, 00)
(AD, 02)
Review Questions
Pass 1
2. EQU
Most assemblers provide an assembler directive that allows the programmer to
define symbols and specify their values, for example. The general form:
symbol EQU value
One common use of EQU is to establish symbolic names that can be used for
improved readability in place of numeric values.
Anothe common use of EQU is in defining mnemonic nanes for registers. For
example:
A EQU 0
X EQU 1
L EQU 2
These statements cause the symbols A, X, L, m to be entered into SYMBOL with
...
their corresponding values 0, 1, 2,.
3. LTORG /
LTORG allows placing literals into a pool at some other location in the object
program.
Directive LTORG creates a literal pool that contains all of the literal operands used
since the previous LTORG or the beginning of the program.
Literals placed in a pool by LTORG will not be repeated in the pool at the end of
the program.
The LTORG statement permits a programmer to specify where literals should be
placed. By default, assembler places the literals after the ENDstatement.
Assembler allocates memory to the literals of a literal pool. The pool contains all
literals used in the program since the start of the program or since the last LTORG
statement.
3.5.2 Pass 1
Assembler
Following data structure is used by Pass 1
1. OPTAB - A table of mnemonic.opcodes and related information.
2. SYMTAB - Symbol table
3. LITTAB - A table of literals used in the program.
Let us consider the following assembly program
START 300
2 MOVER AREG.5 300)04.1 311
+
MOVEM AREGR1 301) 05 1317
AGAIN MOVER AREG, R1 302) +
04 1317
5 MOVER
CREG,R2 303) + 05 3 318
6 ADD
CREG, 1
304? + 01 3 312
*********.
7
12 BC
ANY,TERM 310) + 07 6 314
13 LTORG
= '5 311) + 00 0 005
=1' 312) + 00 0 001
14
15 TERM SUB AREG, = 1' 314) + 02 1 319
16 BC LT, DOWN 315)+ 07 1 302
17 LAST STOP 316) 00 0
000
18 ORIGIN LOOP +2
19 MULT CREG, R2 304) + 03 3 318
20 ORIGIN LAST 1
21 R1 DS 1
e***wa*n* *****Ww. 317)
22 DOWN EQU
wn.sw**w.*.**** ***.******s******w******wv LOOP
23 R2 DS 1
318 ?
24 END
25 = '1 319) + 00 0
001
OPTAB, SYMTAB, LITTAB and POOLTAB contain the following data of the above
given program.
1. OPTAB
2. Symbol table
Symbol Address Length
AGAIN 302 1
TERM 314 1
LAST 316
R1 317
302 1
DOWN
1
R2 318
Literal Addres8
1 =5
2 = 1
3 1
4. POOLTAB
Literal
number
#1
#3
A) OPTAB: It consists of, mnemonic opcode, class and mnemonic. info field. The class
field indicates the statement types, i.e. imperative, declaration and assembler.
B) SYMTAB : It consists of address and length.
:
C) LITTAB It consists of literal and address fields.
Processing of an assembly statement begins with the processing of its label field. If
the label contains a symbol, the symbol and the value in location counter is copied
into a new entry of symbol table.
For imperative statement: The length of the machine instruction is simply added to
the LC. Length is also entered into the SYMTAB entry of the symbol.
Declaration or assembler directive statement: The routine mentioned in the
mnemonic info field is called to perform appropriate processing of the statement. For
example, in the case of a DS statement, routine #7 would be called.
R
First pass uses LITTAB to collect all literals used in a program. Awarness of
different literal pools is maintained using the auxiliary table POOLTAB. This table
contains the literal number of the starting literal of each literal pool. At any stage,
the current literal pool is the last pool in LITTAB.
DC 01 START 01
DS 02 END 02
ORIGIN 03
EQU 04
LTORG 05
Memory operand is the second operand and represented in the following format.
(operand class, code)
where
operand class = C, S or L (any one)
(C= Constant, S = Symbol, L = Literal)
-
TECHNICAL PUBLICATIONs An up thrust for knowledge
System Sofware 3-22 Assemblers
Code field
1) For constant
a) Internal representation of the constant itself
b) e.g. START 300 is (C, 300)
Contains the original number of the operand's entry in SYMTAB or LITTAB. For
example
.
Symbol xyz Literal
=
'25'
(S, 17) (L, 35)
• If the assembly statement contains symbol in the label field, then entry is made in
SYMTAB.
For example, (A, 349, 1) is the entry for symbol A. It allocate one word for A at
memory address of 349.
• For forward reference
MOVER AREG, A
A
is entered in a symbol table at number n. It is represented as (s, n) in IC.
A
this point, the address and length fields of A'sentry cannot be filled in.
Symbol table contains two types, of entry at any time, ie. defined symbols and
forward references.
Varlant lI
.
Following is the program for intermediate code
variant J.
.It differ from variant I in the operand field of the source statements.
Processing of he operand fields is essential to support LC
processnB n
declarative and assembler.
Operand field is processed only to identify literal reference for imperative
statements.
In literal table, literals are entered and represented as (L,
m) in C.
START 300 (AD 01)(C, 300)
Pass 2 Pass 1
Pass 2
Pass 1
Wastage of
memory Datastructures Data structures
(b) Variant II
(a) Variant I
Fig. 3.5.2 Variant I and II
First pass constructs an intermediate This table can be used to fill-up the addresses
representation of the source program and that in incomplete instruction.
will be used by second pass.
Address of symbol can be calculated. Only creates tables with all symbols, no
address of symbol is calculated.
-
TECHNICAL PUBLICATIONS An up thrust for knowledge
3- 26 Assemblers
System Software
pass 1:
a) Siow the contents of the symbol table at the end of
b) Explain the significance of EQU and ORIGIN statement in the
program and explain how
they are processed by the assembler,
c) Show the internediate code generated for the program. GTU Summer-18, Marks 7
:
Solution : Symbol Table
Symbol Address
100
L1 101
D 104
L2 105
C 107
110
Intermediate Code
(AD, 01) (C, 100)
(DL, 02) (C, 3)
(IS, 04) (1) (L, 01)
(IS, 01) (1) (S, 01)
(IS, 05) (1) (L, 02)
(IS, 06) (1) (L, 03)
(AD, 02)
Review. Questions
-
TECHNICAL PUBLICATIONS An up thrust for knowledge
System Software 3-28 Assemblers
10. List out assembler directives and explain any two advance assembler directives.
GTU: Summer-19, Marks 7
tvo pass assembler.
11. Differentiate between one pass and GTU:Winter-19, Marks 4
12. Consider the following asembly language progam and explain role of OPTAB, SYMTAB,
LITTAB, POOLTAB vitlh its contents. GTU : Winter-19, Marks 7
START 300
MOVER AREG, "=5
MOVEM AREG,R1
AGAIN MOVER AREG,R1
MOVER CREG,R2
ADD CREG,='1'
BC ANY,TERM
LTORG
='5'
END
="1'
13. List out various assembler directives. Explain any three in detail. GTU Winter-19, Marks 7
TECHNICAL PUBLICATIONs -
An up thrust for knowledge
Sowere
Sst 3-29 Assemblera
*#eror Invalid
*
opcode
24 R1 DC10 327
error K*
Duplicate dennition of symbol R1.
40 END
Delaying the program listing and error reporting till Pass 2 is possible. It
gives
effective error reporting facility. It is als0 necessary to report all errors against
erroneous statement itself.
Error reporting in Pass 1
From the Fig. 3.6.1, error is detected at statement 10 and 24. Statement 10 gives
invalid opcode error and statement 24 gives duplicate definition error. Staternent
10 does not match with any mnemonic in OPTAB. Entry of R1 already
exists in
symbol table so statement 24 gives error.
Symbol R2 is undefined so it is harder to detect. Because at the end of
Pass 1,
there is no record that a forward reference to R2 exist in statement 15. At
of Pass 1, all the entries would be processed for checking the definition
the end
of the
symbol has been encountered.
Error reporting in Pass 2
Following Fig. 3.6.2 shows Pass 2 error reporting.
Sr. No. Statement Address Instruction
01 START 300
02 MOVER AREG, R1 300 1 309
24 R1 DC '10 327 00 0
010
** error ** Duplication definition of symbol R1
40 END
Fig. 3.6.2 Pass 2 errorreporting
In Pass 1, error reporting at statement 10 and 24 is easy, Error indication at
statement 14 is also easy because the symbol table is an searched for entry K
Source
program
(user)
Pass I
|Opcode
table
Source
program
Symbol|i
table
Intermediate
Literal Çode
table
Pass II
Program Required
listing target
program
SIMPLE START
BALR 15, 0
USING *, 15
R1, TWO
LOOP
TECHNICAL PUBLICATIONs
-
An up thrust for knowledge
System Software 3-32 Assembler
R1, FOUR
ST R1, FOUR 8
CLI FOUR +3, 4 12
BNE LOOP 16
BR 14 20
RI EQU 24
TWO DC F2 28
FOUR DS 32
END
Pass 2 database,
1. Copy of source program input to Pass 1.
2. Location counter.
3. MOT represents the following for each
instructions:
a) Symbolic mnemonic
b) Length
c) Binary machine opcode
d) Format
4. POT is used for each pseudo-op the symbolic mnemonic and the action to be taken
in Pass 2.
TECHNICAL PUBLICATIONS® - An up
thrust for knowledge
System Sofiware 3- 33 Assomblors
5, Pass 1
prepared the symbol table which contains label and its corresponding value.
6. Base Table indicates which registers are
currently specified as base registers by
using pseudo-ops.
7. A work space is used to hold each instruction as its various parts are
being
assembled together.
8. A work space (PRINT LINE)
used to produce'a printing listing.
9. A work space (PUNCH
CARD) also used for outputting.
10. An output desk of assembled
instructions in the format needed by the loader.
5A 10 001
"AH- 4A 10 001
"AL 5E 10 001
"ARbH" 1A 01 000
"DROP." PIDROP
"END-" P1END
"EQU-" PIEQU
"START-" P1START
"USING-" P1USING
Pass 1
Fig. 3.7.3 POT for
The Symbol Table and Literal Table includes for each entry. It also contains a
length field and a relative-location indicator. The length field indicates the lenoth
of the instruction or data to which the symbol is attached."
The relative location specify the value of the symbol to the assembler. Value of the
symbol is absolute or relative to thebase of the program.
Symbol table for Pass 1 and Pass 2
Assembler uses relative location to identify the symbol value. Symbol value may
be relative or absolute to the base of the program. If constant value is used for
defining the symbol, then the symbol is bsolute. Otherwise- it is consider as a
relative.
Symbol table uses "R" for specifying relative and "A" for specifying the absolute
location.
Pass 1 flowchart
Start
Pass 1
Initialize LC
L=Length
Go to
Pass 2
Process literals
Symbol Yes
in label Assign current value
field
of LC to symbol
LC = LC+L
Pass 2
Initialize LC
Readcard
form file copy
Search Yes
pseudo-op table DS EQU DROP
No
tDC START USING END
Adjust LC Evaluate
Search to proper operand
machine-op tabe alignment
Shows base
Get op-code byte reg. number
and format code, Fom constant Enter base unavallabe
DC and insert in reg. no. and
L= Length or
DS assembled value into
program
base table
Type of DS
instruction
L= length
RR of data field
Evaluate both Printing listing
register expressions
and insert into RX
2nd byte
Evaluate register and
index expressions
"Punch" and insert into
assembled 2nd byte
instruction
Generates iterals
Calculate effective for entries in
Display address of operand Literal Table
assembly
listing line
D+C(B)=EA STOP
| LC= LC+L
Put B&D into
bytes 3 and 4
TECHNICAL PUBLICATIONS -
An up thrust for knowledge
Software
System 3-37 Assemblers
o Assembler uses a
base table for generating
machine instruction and calculates the proper base register reference in
the correct offsets. Base register helps to an
assembler for generating an address. An
address contains offset, a base register
number and an index register number.
Ofset = (Value of symbol in symbol table) -
(ontent of base register)
Review Question
2. Insert the symbol into SYMTAB and mark this symbol undefined
3. The address that refers to the undefined symbol is
added to a list of forward
references associated with the symbol table entry
4 When the definition for a symbol is encountered, the proper address for the
symbol is then inserted into any instructions previous generated according to
the forward reference list
A one-pass assembler scans the program just once. The main problem in trying to
assemble a program in one pass involves forward references.
Can we write a program without forward references ?
All storage reservation statements can be defined before they are referenced. But,
forward references to labels on instructions cannot be eliminated as easily. The
logic of the program often needs a forward jump.
The one-pass assembler must make some special provision for handling forward
references. One-pass assembler are of two types
:
1. One type of one-pass assemblers produces object code directly in memory for
immediate execution. No object program is written out and no loader is
needed.
2. The other type of one-pass assemblers produces the usual kind of object
program for later execution.
The assembler that does not write object program out and does not need a loader
is called a load-and-go assembler.
It avoids the overhead of
writing the object
program out and reading
Source Load-and-go Program
it back in. It is useful in
program assembler loaded
a system that is oriented in memory
toward program
development and testing.
A load-and-go àssembler Assembler
can be one-pass assembler
or a two-pass assembler. Fig. 3.8.1 Load and go assembler
Fig. 3.8.1 shows the
concept of load-and-go
assembler.
Handling of forward references in one-pass load-and-go assembler
1. The assembler generates object code instructions as it scans the source program. If
an instruction operand is a symbol that has not yet been defined. The symbol is
entered into the symbol table with a flag indicating that the symbol is undefined.
2. The operand address is omitted when the instruction is assembled; the operand
address is added to a list of forward references associated with the symbol table
entry.
3. When the definition for a symbol is encountered, the forward reference list for that
symbol is scanned, and the proper address is inserted into any instructions
previously generated.
One-pass assemblers that product object programs as output are often used on
systems where external working-storage device for the intermediate file between
the two passes are not available and systems with slow external storages.
Forward references are entered into lists as before. Object code without addresses
of undefined operands can be written out as part of a Text record in the object
program.
When the definition of a forward reference is encountered, the assembler generates
Text records with the correct operand address. In effect, the services of the loader
are being used to complete forward references that could not be handled by the
assembler.
When the program is loaded, this address will be inserted into the instruction by
the action of the loader.
One-Pass Assemblers
One-pass assembler generates their object code in memory for immediate
execution. No object program is written out and no loader is needed. This kind of
load-and-go assembler is useful in the system that is oriented
towards program
development and testing.
.A load-and-go assembler avoids the overhead of writing the object program out
and reading it back in. This can be accomplished with either a one or two pasS
assembler. HOwever, a one pass assembler also avoids the overhead of an
additional pass over the source program. Because the object program is
produced
in memory rather than being written out on secondary storage, handling of
forward references becomes less difficult.
The assembler simply generates object code instructions as it scans the source
progranm.
Fig. 3.8.2 shows the sample program for a one-pass assembler.
120
INPUT BYTE XF1 F1
121 2039
MAXLEN WORD 4096 001000
122 203A
24
Symbol Value
LENGTH
1000
RDREC
2013
THREE 1003
ZERO 1006
WRREC
201F
EOF 100D
ENDFIL
201C
RETADR 1009
BUFFER 100F
CLOOP 2012
FIRST 200F
Fig. 3.8.3
•Now consider Fig. 3.8.4, which corresponds to the situation after scanning
lne 160.
By this time, some of the forward references (ENDFIL, Line 45 and RDREC line
125) have been resolved, while others (EXIT, line 175 and WRREC,
line 210) have
been added.
When the symbol ENDFIL was defined, the assembler placed its value in the
SYMTAB entry; it then inserted this value into the instruction operand
feld (at
address 201C) as directed by the forward reference list. From this point on, any
references to ENDEIL would not be forward references and would not be entered
into a list.
At the end of the program, any SYMTAB entries that are still marked with s
indicate undefined symbols. These should be flagged by the assembler as errors.
One-pass assemblers that produce object programs follow a slightly different
procedure from that previously described.
1) Forward references are entered into lists as before.
2) When the definition of a symbol is encountered, instructions that made
forward references to that symbol may no longer available in mnemory for
modification. In general, they will already have been written out as part of a
Text record in the object programn. In this case, the assembler must generate
another Text record with the correct operand address.
TECHNICAL PUBLICATIONS - An up thrust for knowledge
System Softwaro Assemblors
3- 42
Symbol Value
LENGTH 100C
RDREC 203D
THREE 1003
ZERO 1006
WRREC |*
201F - 2031
EOF 1000
ENDFIL 2024
RETADIR 1009
BUFFER 100F
CLOOP 2012
FIRST 200F
MAXLEN 203A
INPUT 2039
EXIT 2050
RLOOP 2043
Fig. 3.8.4
3) When the program is loaded, this address will be inserted into the instruction
by the action of the loader.
The 2nd Text record contains that object code generated from lines 10 through 40
in Fig. 3.8.2. The operand addresses for the instructions on lines 15, 30 and 35
have been generated as 0000.
When ENDFIL on line 45 is encountered, the assembler generates the 3" Text
record. This record specifies that the value 2024 (the address of ENDEIL) to be s
loaded at location 201C (the operand address field of JEQ on line 30).
When the program is loaded, the value 2024 will replace the 0000 previously
loaded.
Forward Reference in One-Pass Assembler
1. Omits the operand address if
the symbol has not yet been defined.
2. Enters this undefined symbol into SYMTAB
and indicates that it is undefined.
TECHNICAL PUBLICATIONS- An up thrust for knowledge
Sovam 3- 43 Angomblora
Syston
a
Adls the addregs ol lhis operand addlress to list of forward references associated
with the SYMTAB entry.
A
When the definilion for the symbol is encountercd, scans the reference list and
inserts the address.
E Át the end of he program, reports tlhe error if there are still SYMTAB entries
indicated undefincd symbols.
6 For Load-and-Go assenmbler : Scarch SYMTAB for the syrnbol narmed in the END
statement and jumps to this location to begin cxecution if there is no erro.
IF
One-Pass Assemblers Need to Produce Object Codes
When external working storage devices are not available or too slow then the
:
solution is as follows
1. If the operand contains an undefined symbol, use 0 as the address and write
the Text record to the object program.
2. Forward references are entered into lists as in the load-and-go assembler.
3. Whe the definition of.a symbol is encountered, the assernbler generator
another text record with the correct operand address of each entry in the
reference list.
4. When loaded, the incorrect address 0 will be updated by the latter text record
containing the symbol definition.
Review Question
Literal Pools
All of the literal operands used in a program are gathered together into one or
more literal pools.
Normally literals are placed into a pool at the end of the program.
In some cases, it is desirable to place literals into a pool at some other location in
the object program. For this purpose, the assembler directive LTORG is used.
1. When the assembler encounters a LTORG statement, it creates a literal pool
that contains all of the literal operands used since the previous LTORG.
2. This literal pool is placed in the object program at the location where the
LTORGdirective was encountered.
3. Literal placed in a pool by LTORG will not be repeated in the pool at the end
of the program.
Duplicate Literals
The assemblers should recognize duplicate literals and store only one copy of the
specified data value. For example
215 1062 WLOOP TD = X'05'
230 106 B WD= X'05'
Only one data area with this value is generated. Both instruction refer to the same
address in the literal pool for their operand.
How to find the duplicate literals ?
1) The easiest method is to recognize duplicate literals is
by comparison of the
character strings defining them. Same literal name with different value
e.g. LOCCR = *
2) Comparison of the generated data value. The benefits of using generate data
value are usually not reat enough to justify the additional complexity in the
assembler.
The basic data structure that assembler handles literal operands is literal table
LITTAB. For each literal used, this table contains the literal name, the operand
TECHNICAL PUBLICATIONS -
An up thrust for knowledge
System Software 3- 45 Assemblers
Pass
) Build LITTAB with literal name, operand value and lerngth, leaving the address
unassigned.
2 When LTORG statement is encountered, assign an address to each literal not yet
assigned an address.
Pass 2
1) Search LITABfor each literal operand encountered.
2) Generate data values using BYTE or WORD statement.
3)Generate modification record for literals that represent an address in the program.
o
Following are the parameter which affects the pass structure of an assembler.
1. Translationtime
2. Storage area
3. Efficiency of target code
4. Speed of translation
5. Error listing
6. Overheads
O
Single pass assembler translation time is more than the multipass assembler
because there are more than one pass.
o Multipass assembler requires less memory for loading because memory allocated
to Pass 1 is reused by Pass 2.
o
In multipass assembler the code generated by the first pass is called intermediate
code. This is stored on secondary storage device, which involves I/0 operations,
due to which speed of multipass assembler slows down. So single pass assembler
is better.
o
The code generated by assembler should be efficient in terms of executation speed.
It is not possible to declare error immediately in one pass assembler but errors can
be displayed more precisely if we use more than one passes.
Review Question
L. Explain the difference between literal and constant in assembler with its syntax. Why PO0LTAB
:
is requiring ? GTU Winter-17, Marks 3
3.10 Expressions
a
Most assembler allow the use of expressions whenever such single operand is
permitted. Each such expression must be evaluated by the assembler to produce
single operand address or value.
Expressions can be classified as absolute expressions or relative expressions
depending upon the type of value they produce.
Relative expressions : Relative means relativ to the beginning of the program
Labels on instuctions and data areas, and references to the location counter valhue
are relative terms. No relative term nay enter into a multiplication or division
operation.
Absolute : Absolute means independent of program location. A constant is an
absolute term. Absolute exprssions may also contains relative termns provided the
relative terms occur in pair and the terms in each such pair have opposite sign.
A relative term or expression represents some value that may be written as
(S + r) where
S = Starting address of the program
BUFFER R 0036
BUFEND R 1036
MAXLEN 1000
With this information, the assemnbler can easily determine the type of each express1On
used as an operand and generate modification records in the object program for relative
values.
Name Value
COPy
FIRST 0
CLOOP 6
ENDFIL 1À
RETADR 30
LENGTH 33
BUFFER 36
BUFEND 1036
MAXLEN 1000
RDREC 1036
RLOOP 1040
EXIT 1056
IINPUT 105C
WREC 105D
WLOOP 1062
LITTAB
X'05 05 1076
Solved Examples
Syntax Addr
Again 1003
N 1013
Result 1014
Term 1034
Literal table
=
/' 1011
Intermediate code
Read 3A
MOVER 3B
MOVEM 3C
MULT 3D
ADD 3E
COMP 3F
BC 3G
Print AA
Stop AB
Target code
B - Register #2
-
C
Register #3
1014
1034
1035 end
Example 3.11.2
START 100
MOVER AREG,= 5
ADD CREG,= 1
A DS 3
L1 MOVER AREG,b
Add AREG,C
MOVEM AREG,d
L TOR G
D EQU A+1
L2 Print D
ORIGIN A-1
SUB AREG,1
MULT CREG,b
DS
ORIGIN L2+1
STOP
B DC 19
END
i) Shou the contents of symbol table, literal. table and poo! table at the end of
pass I.
i) Show the intemediate code generated for the program.
Solution : Symbol table :
L1 4 1
4 4
L2 4 4
B 19 1
Literal table :
areg = 1 56 4
Intermediate code
MOVER AREG 5
ADD CREG 1
MOVER AREG b
ADD AREG C
MOVEM AREG d
SUB AREG 1
MUL CREG b
Print D
Stop
Q.4 The assembler·in first pass reads the program to collect symbols defined with offsets
in a table
a Literal table b Hash table
Symbol table POT table
Q.5 The must contain at least the mnemonic operation code and its machine
language equivalent.
a Symbol table Literal table
C Operation code table d Program counter
Q.6 An assembler is
a programming language dependent. b syntax dependant.
machine dependant. d data dependarnt.
Q.7 In a two-pass assembler, the task of the Pass II is to
a separate the symbol, mnemonic opcode and operand fields.
build the symbol table.
construct intermediate code.
d synthesize the target program.
TECHNICAL PUBLICATIONS - An up
thrust for knowiedge
System Sofware 3-54 Assemblers
c d
language) into target instructions (in machine language), on a one to one basis.
Q.2 Define assembler directives.
Ans. Assembler directive instruct the assembler to perform certain action during the
:
assembly program.
Q.3 What is a program block ?
Ans. Program block refer to segments of code that are rearranged within a single
:
object program unit and control sections to refer to segments that are translated into
independent object program unit.
Q.4 What is a common use of ORG ?
Ans. : The most common use for ORG is to specify a start address for the program in
a computer without an operating system.
Q.5 List three types of assembly language statements ?
Ans. : Three types of assembly language statements are :
Imperative statements,
Declaration statements and Assembler directives.
Q.6 What is symbol table ? GTUSummer-17 Mark I
Ans. : Each entry in the table contains the definition of a symbol and has fields for the
name, value, and type of the symbol.