Mod 3 Class 4 - Machine Independent Assembler Features (Part 1)
Mod 3 Class 4 - Machine Independent Assembler Features (Part 1)
Chap 2
Machine-Independent Assembler
Features
1. Literals
2. Symbol Defining
Statement
3. Expressions
4. Program Blocks
5. Control Sections and
Program Linking
1. Literals
● Design idea
● Let programmers to be able to write
the value of a constant operand as a
part of the instruction that uses it.
● This avoids having to define the
constant elsewhere in the program
and make up a label for it.
Chap 2
Example (fig 2.9)
45 ENDFIL LDA =C’EOF’
93 LTORG
Chap 2
Program with Object code (fig 2.10)
45 001A ENDFIL LDA =C’EOF’ 032010
93 LTORG
002D * =C’EOF’ 454F46
Chap 2
Literal - Implementation (1/3)
● Literal pools
● Normally literals are placed into a pool at
the end of the program
● see Fig. 2.10 (END statement)
Chap 2
Literal - Implementation (2/3)
● Duplicate literals
● e.g. 215 1062 WLOOP TD =X’05’
● e.g. 230 106B WD =X’05’
● The assemblers should recognize duplicate
literals and store only one copy of the
specified data value
Chap 2
Literal - Implementation (3/3)
● LITTAB
● literal name, the operand value and length, the
address assigned to the operand
● Pass 1
● build LITTAB with literal name, operand value
and length, leaving the address unassigned
● when LTORG statement is encountered, assign
an address to each literal not yet assigned an
address
Chap 2
● Pass 2
● search LITTAB for each literal operand
encountered
● generate data values using BYTE or WORD
statements
● generate modification record for literals that
represent an address in the program
Chap 2
2. Symbol-Defining Statements
● Labels on instructions or data areas
● the value of such a label is the address
assigned to the statement
● Defining symbols
● symbol EQU value
● value can be: constant, other symbol,
expression
● making the source program easier to
understand
● no forward reference
Chap 2
Symbol-Defining Statements
● Example 1
● MAXLEN EQU 4096
● +LDT #MAXLEN +LDT #4096
Chap 2
ORG (origin)
● Indirectly assign values to symbols
● Reset the location counter to the specified value
● ORG value
● Value can be: constant, other symbol,
expression
● No forward reference
● Example
● SYMBOL: 6bytes
● VALUE: 1word
● FLAGS: 2bytes
● LDA VALUE, X
Chap 2
ORG Example
● Using EQU statements
● STAB RESB 1100
● SYMBOL EQU STAB
● VALUE EQU STAB+6
● FLAG EQU STAB+9
● Using ORG statements
● STAB RESB 1100
● ORG STAB
● SYMBOL RESB 6
● VALUE RESW 1
● FLAGS RESB 2
● ORG STAB+1100
Chap 2
Expressions
● Expressions can be classified as absolute
expressions or relative expressions
● MAXLEN EQU BUFEND-BUFFER
● BUFEND and BUFFER both are relative terms,
representing addresses within the program
● However the expression BUFEND-BUFFER represents
an absolute value
● When relative terms are paired with opposite
signs, the dependency on the program starting
address is canceled out; the result is an absolute
value
Chap 2
SYMTAB
● None of the relative terms may enter into a
multiplication or division operation
● Errors:
● BUFEND+BUFFER
● 100-BUFFER
● 3*BUFFER
● The type of an expression
● keep track of the types of all symbols defined in
the program
Chap 2
Example 2.9
SYMTAB LITTAB
Chap 2
Program Blocks
● Program blocks
● refer to segments of code that are rearranged
within a single object program unit
● USE [blockname]
● Default block
● Example: FigureExample: Figure 2.11
● Each program block may actually contain
several separate segments of the source
program
Chap 2
Program Blocks - Implementation
● Pass 1
● each program block has a separate location counter
● each label is assigned an address that is relative to the
start of the block that contains it
● at the end of Pass 1, the latest value of the location
counter for each block indicates the length of that block
● the assembler can then assign to each block a starting
address in the object program
● Pass 2
● The address of each symbol can be computed by
adding the assigned block starting address and the
relative address of the symbol to that block
Chap 2
Figure 2.12
● Each source line is given a relative address
assigned and a block number
Chap 2
Chap 2
Chap 2