Professional Documents
Culture Documents
CONTENTS
1 ABSTRACT 2
2 INTRODUCTION 3
EXAMPLE 6
LITERAL HANDLING 11
ONE PASS THE ASSEMBLER 12
6 RESULTS 19
7 CONCLUSION 21
8 REFERENCES 22
2
2 PASS ASSEMBLER FOR 8085
ABSTRACT:
2 pass Assembler
Pass 1
Assign addresses to all statements in the program
Save the values assigned to all labels for use in Pass 2
Perform some processing of assembler directive
Pass 2
Assemble instructions
3
2 PASS ASSEMBLER FOR 8085
INTRODUCTION:
4
2 PASS ASSEMBLER FOR 8085
5
2 PASS ASSEMBLER FOR 8085
the mnemonics by machine codes, symbols by the corresponding addresses and generates the
output.
JPOS 06 1 2 JZ if ACC>0
GOTO L
JZ 07 1 2 JZ L if ACC=0
GOTO L
6
2 PASS ASSEMBLER FOR 8085
1 READ N
2 LOAD ZERO
3 STORE COUNT
4 STORE SUM
5 LOOP READ X
6 LOAD X
7 ADD SUM
8 STORE SUM
9 LOAD COUNT
10 ADD ONE
11 STORE COUNT
12 SUB N
13 JZ OUTER
14 JMP LOOP
15 OUTER WRITE SUM
16 STOP
17 ENDP
18 ZERO
19 ONE
20 SUM DEFW
21 COUNT DEFW
22 N DEFW
23 X DEFW
24 END
7
2 PASS ASSEMBLER FOR 8085
8
2 PASS ASSEMBLER FOR 8085
Processing of lines 2, 3, and 4 is similar. When we come to line 5 LC becomes eight and
the symbols ZERO, COUNT, SUM have been inserted in the ST. The specialty of line 5
is that it has a label field “LOOP”, The label Loop can be used elsewhere in the program
only to transfer control to line 5i.e. to word 8(the current value of the location counter).
To remember this information for subsequent use, the name Loop and its attribute (with
value 8) is inserted inside the symbol table. Proceeding in this manner, we can continue
up to line 17 inserting the new symbols as encountered in the symbol table and updating
the location counter. The symbol table now contains the following information.
N Id ---
ZERO Id ---
COUNT Id ---
SUM Id ---
X Id ---
LOOP Id 08
ONE Id ---
OUTER Id 28
Note that, the type field can be seen to identify whether a symbol represents a label or an
identifier. T he significance of “ other” fields will be clarified later. The current value of
LC is clearly 31. In line 17, the assembler comes across a pseudo-op ENDP. So the
assembler next searches a similar table called the pseudo operation table (POT), which
contains information regarding all pseudo ops. Unlike mnemonics for machine codes, a
pseudo-op does not always alter the value of the LC. Hence LC remains 31 at the end of
line 17. Seeing the ENDP assembler directive, which signifies the physical end of the
program segment, the assembler can conclude that the remaining free memory words
may be used to store the data.
In line 18, the pseudo-op CONST indicates that the label ZERO is defined as a constant
having the value 0. The assembler then search for the entry of the symbol ZERO is
ST(creates one is not found) puts the LC value (31) as its address and keeps a tag to
9
2 PASS ASSEMBLER FOR 8085
remember that it is a constant so that any attempt to overwrite ZERO can be reported as
an error. LC is incremented by 1. When we come to line 20, a new pseudo-op DEFW is
found. Processing of DEFW is similar to that of CONST expect that it is marked as a
variable identifier. Once we come to END in line 24, which indicates the end of the
source text symbol table will be updated as shown below.
N Var Id 35
ZERO CONST Id 31
COUNT Var Id 34
SUM Var Id 33
X Var Id 36
LOOP LABEL 08
ONE CONST Id 32
OUTER LABEL 28
Now after scanning the entire source text, we are in a position to say the amount of
storage necessary for the instructions, the storage required by the data segment and the
addresses, each symbol should refer to. Recall that while scanning line 1, the assembler
reserved one word for the address of N. But since this address was not known the content
of word 1 had to remain undefined till the availability of the address of N. Actually
replacing such symbolic references is deferred until the end of pass one when unresolved
attributed of all symbols are expected to be completed. The assembler is now equipped
with all necessary information so that it can start generating the object code by going
through the source code for the second time. For example, the object code of the program
in Example1 can easily be generated as follows:
10
2 PASS ASSEMBLER FOR 8085
7 33
5 LOOP READ X 8 10
9 36
6 LOAD X 10 08
11 36
7 ADD SUM 12 01
13 33
8 STORE SUM 14 09
15 33
9 LOAD COUNT 16 08
17 34
10 ADD ONE 18 01
19 32
11 STORE COUNT 20 09
21 34
12 SUB N 22 02
23 35
13 JZ OUTER 24 07
25 28
14 JMP LOOP 26 04
27 08
15 OUTER WRITE SUM 28 11
29 33
16 STOP 30 12
17 ENDP
18 ZERO CONST 0 31 00
19 ONE CONST 1 32 01
20 SUM DEFW 33 XX
21 COUNT DEFW 34 XX
22 N DEFW 35 XX
23 X DEFW 36 XX
24 END
Note that the output has been written in decimal for case of understanding. Actually, the
assembler generates the output in binary. The data generation part (lines 18 to 23) needs
11
2 PASS ASSEMBLER FOR 8085
some more explanation. Consider line 18. In the first pass, the assembler assigns a value
(equal to 0) to that address. While processing the directive “DEFW” in the second pass,
only storage is reserved and it is not necessarily initialed with some specific value. To
indicate that contents of word 33-36 have been marked XX. However, some assemblers
might as well assign some value, possibly 0, to those words. The program in Example 1
and its translated version identify the major tasks of an assembler and also explain how
those tasks are performed. Let us now more formally present an assembler in an
algorithm form.
LITERAL HANDLING
An operand whose value is literally stated is called a literal. For example consider the
following two Add commands: (i) ADD A (ii) ADD @21.
In (i) ‘A’ refers to some memory location whose content is to be added.
In (ii), the intension is to add the value 21 (not the content of some explicitly stated
memory address as in (i)). So, 21 is a literal. The purpose of the special symbol @ is to
inform the assembler that what follows it is to be treated as a literal. Literals are very
useful for writing program.
In the first pass, the assembler puts the literals in a table Known as Literal Table.
The literal table consists of three fields, the literal, its corresponding address and the
value. The fields specified at the end of pass1. The data is also generated and the value
field is initialized. In pass 2; the assembler can easily replace the literals by their
addresses.
12
2 PASS ASSEMBLER FOR 8085
The 8085 is an 8bit general purpose microprocessor capable of addressing 64K words
of memory. The microprocessor requires a 5volts power supply and can operate at a
3MHZ single phase clock. The functional diagram of 8085 microprocessor is given in
figure the Arithmetic Logic Unit (ALU) includes 8bit accumulator, a temporary
register, arithmetic and logic circuits and five flags. It has six general purpose registers
identified as B, C, D, E, H and L. They can be combined as register pair BC, DE, and
HL in order to perform sixteen bit operations. The accumulator is identified as A.
13
2 PASS ASSEMBLER FOR 8085
Control Bus
Interrupt control
8 Bit intern
Accumulator
(8) Tem
Fig.2: FUNCTIONAL ORGANIZATION OF p.
THE 8085
Reg. (8)
The instruction set of 8085 may be classified into the following function categories:
(i) Data transfer, (ii) arithmetic operations, (iii) logical operations, (iv) branching
operations, (v) machine control operations and (vi) assembler directives.
The brief description of the subset of the entire instruction set given in table. Each
instruction contains an op-code and may also have an operand. The op-code is 8 bit
wide. The operand includes an internal register, 8 bit or 16 bit data, a memory location
Flag(5)
and 8 or 16 bit address.
Flip-Flops
14
2 PASS ASSEMBLER FOR 8085
15
2 PASS ASSEMBLER FOR 8085
A 111
B 000
C 001
D 010
E 011
H 100
L 101
M 110
The following data structures and databases are to be maintained to design the assembler for
8085.
1) A file containing the input source program.
2) The Machine Operation Table (MOT). An entry in MOT contains a
mnemonic, its machine code and the length of the instruction.
3) The Pseudo Operation Table (POT) which contains the list of all the
assembler directives.
4) The Symbol Table (ST).
5) The Literal Table (LT).
6) The intermediate file and the output file (.obj).
16
2 PASS ASSEMBLER FOR 8085
17
2 PASS ASSEMBLER FOR 8085
18
2 PASS ASSEMBLER FOR 8085
19
2 PASS ASSEMBLER FOR 8085
RESULTS
1) INPUT FILE
LXI H, 0000
MVI C, 00
MOV A, M
INX H
ADD M
JNC LAB1
INR C
LAB1: INX H
MOV M, A
INX H
MOV M, C
HLT
2) SYMBOL TABLE
3) INTERMEDIATE FILE
m80-r6-C-A16-0000
m23-r3-C-A8-00
m22-r1-C-r9
m20-r6
m3-r9
m70-l-s1
m19-r3
l-s1-cn-m20-r6
m22-r9-C-r1
m20-r6
m22-r9-C-r3
m17
20
2 PASS ASSEMBLER FOR 8085
4) OUTPUT FILE
PC Opcode OBJCODE
________________________________________
0005 MOV A , M 7E
0006 INX H 23
0007 ADD M 86
000B INR C 0C
000D MOV M , A 77
000E INX H 23
000F MOV M , C 71
0010 HLT 76
21
2 PASS ASSEMBLER FOR 8085
CONCLUSION
This project generates the object code for 8085 microprocessor. It takes assembly
language as input, and generates object code as output. And this is done with 2 passes. During
the pass1 phase it generates symbol table and an intermediate code. In pass2 phase it takes
intermediate file as input and updates the symbol table and generates the object code.
22
2 PASS ASSEMBLER FOR 8085
REFERENCES
[1] Donovan J.J., “System Programming”, Mc-Graw Hill, New York, 1972.
[2] Barron D. W., “Assemblers and loaders, 2/e”, Elsevier, New York, 1972.
Addison-Wesley, 1985.
Addison-Wesley, 1976.
23