Professional Documents
Culture Documents
1. Introduction
There are two main classes of programming languages: high level (e.g., C, Pascal) and low
level. Assembly Language is a low level programming language. Programmers code symbolic
instructions, each of which generates machine instructions.
An assembler is a program that accepts as input an assembly language program (source) and
produces its machine language equivalent (object code) along with the information for the loader.
Linker
EXE
Disadvantages:
Not portable
More complex
Requires understanding of hardware details (interfaces)
Assembler:
An assembler does the following:
1. Generate machine instructions
- evaluate the mnemonics to produce their machine code
- evaluate the symbols, literals, addresses to produce their equivalent machine addresses
- convert the data constants into their machine representations
2. Process pseudo operations
Data Structures:
Location counter (LC): points to the next location where the code will be placed
Op-code translation table: contains symbolic instructions, their lengths and their op-codes (or
subroutine to use for translation)
String storage buffer (SSB): contains ASCII characters for the strings
Configuration table: contains pointer to the string in SSB and offset where its value will be inserted
in the object code
assembly
language
program
Pass1
Pass 2
Symbol table
Configuration table
String storage buffer
Partially configured object file
machine
language
program
assembly language
program
----------------------START 0100H
LDA
#5
LOOP: SUB
#1
COMP #0
JGT
LOOP
RSUB
memory
address
object code
in memory
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
01
00
05
1D
00
01
29
00
00
34
01
03
4C
00
00
placed in Pass 1
END
Op-code Table
Symbol Table
Mnemonic
LDA
SUB
COMP
LDX
ADD
TIX
JLT
JGT
RSUB
Addressing mode
immediate
immediate
immediate
immediate
indexed
direct
direct
direct
implied
Opcode
01
1D
29
05
18
2C
38
34
4C
Symbol
LOOP
Value
0103
assembly language
program
----------------------START 0100H
LDA
#0
LDX
LOOP: ADD
TIX
JLT
#0
LIST, X
COUNT
LOOP
RSUB
LIST:
WORD 200
COUNT: WORD 6
memory
address
object code
in memory
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
010A
010B
010C
010D
010E
010F
0110
0111
0112
0113
0114
0115
0116
0117
01
00
00
05
00
00
18
01
12
2C
01
15
38
01
06
4C
00
00
00
02
00
00
00
06
END
Symbol Table
Symbol
LOOP
LIST
COUNT
Address
0106
0112
0115
Configuration Table
Offset
0007
000A
DC00
DC01
DC02
DC03
DC04
DC05
SSB pointer
for the symbol
DC00
DC05
SSB
4CH
49H
53H
54H
5EH
placed in Pass 2
placed in Pass 2
placed in Pass 1
Pass1
All symbols are identified and put in ST
All op-codes are translated
Missing symbol values are marked
LC = origin
Y
Comment
N
END
Pass 2
pseudo-op
what
kind?
N
Label
EQU
WORD/
BYTE
RESW/RESB
Y
N
Enter label in ST
Label
Label
Enter label in ST
Y
Enter label in ST
Y
Enter label in ST
Call translator
Place constant in
machine code
Advance LC
Advance LC by the
number of bytes specified
in the pseudo-op
Translator Routine
Find opcode and the number of bytes
in Op-code Table
more
information
will be needed
in Pass 2 ?
N
Y
Set up an entry in
Configuration Table
return
More lines in
Configuration
Table
N
Done
Y
Get the next line
Assembler
Example 3: Following relocatable object code and DAT are generated for Example 1.
assembly language
program
----------------------START
LDA
#0
LDX
LOOP: ADD
#0
LIST, X
TIX
COUNT
JLT
LOOP
RSUB
LIST:
WORD 200
COUNT: WORD 6
memory
address
object code
in memory
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B
000C
000D
000E
000F
0010
0011
0012
0013
0014
0015
0016
0017
01
00
00
05
00
00
18
00
12
2C
00
15
38
00
06
4C
00
00
00
02
00
00
00
06
END
DAT
0007
000A
000D
Forward and backward references in the machine code are generated relative to address 0000. To
relocate the code, the loader adds the new load-point to the references in the machine code which are
pointed by the DAT.
7
One-Pass Assemblers
Two methods can be used:
- Eliminating forward references
Either all labels used in forward references are defined in the source program before they are
referenced, or forward references to data items are prohibited.
- Generating the object code in memory
No object program is written out and no loader is needed. The program needs to be re-assembled
every time.
Multi-Pass Assemblers
Make as many passes as needed to process the definitions of symbols.
Example 3:
A
B
C
EQU B
EQU C
DS
1
Such references can also be solved in two passes: entering symbol definitions that involve forward
references in the symbol table. Symbol table also indicates which symbols are dependent on the values
of others.
Example 4:
A
B
C
D
EQU
EQU
EQU
DS
B
D
D
1
0
A
0
B
0
0
0
8
200