Pass Structure of Assembler Subject : Systems Programming
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Single Pass Assembler Forward reference: reference to a label that is defined
later in the program. What is Forward reference ??Eg..
START ADD
200 AREG
..
..
A
DS
..
..
A 2
END
Table of Incomplete Instruction
Instruction Address 200 ..
Symbol A ..
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Single Pass Assembler Forward reference: reference to a label that is defined
later in the program.
Symbol A
Address
START ADD
200 AREG
..
..
A
DS
..
..
A 2
END
Table of Incomplete Instruction Instruction Address 200 ..
Symbol A ..
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Single Pass Assembler Forward reference: reference to a label that is defined later in the program.
START 200 ADD AREG ..
..
A
DS
..
..
Target Code A 2
200
01
01
-
…
..
..
..
202
END
Table of Incomplete Instruction Instruction Symbol Address 200 A .. ..
Symbol A ..
Address 202 ..
Target Code 200 01 01
202
..
..
..
..
202
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Single pass Assembler Examples
SOURCE PROGRAM
AGAIN
TARGET CODE
START
101
READ
N
MOVER
BREG,
ONE
MOVEM
BREG,
TERM
MULT
BREG,
TERM
MOVER
CREG,
TERM
ADD
CREG,
MOVEM COMP BC MOVEM PRINT
INSTRUCTI ON Address
SYMBOL
101
N
101
09
-
102
04
02
-
102
ONE
103
05
02
-
103
TERM
104
03
02
-
104
TERM
105
04
03
-
105
TERM
ONE
106
01
03
-
106
ONE
CREG,
TERM
107
05
03
-
107
TERM
CREG,
TERM
108
06
03
-
07
02
104
108
TERM
AGAIN
109
05
02
-
110
RESULT
RESULT
110 111
10
-
111
RESULT
112
00
LE, BREG, RESULT
STOP N
DS
1
RESULT
DS
1
ONE
DC
‘1’
TERM
DS
1
END
TII
113 114 115 116
Symbol Table SYMBOL
ADDRESS
N
113
ONE
115
TERM
116
RESULT
114
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Single pass Assembler Examples SOURCE PROGRAM
AGAIN
N
TARGET CODE
START
101
READ
N
MOVER
BREG,
ONE
MOVEM
BREG,
TERM
MULT
BREG,
TERM
MOVER
CREG,
TERM
ADD
CREG,
ONE
MOVEM
CREG,
TERM
COMP
CREG,
TERM
BC
LE,
MOVEM
BREG,
RESULT
TII
INSTRUCTI ON Address
SYMBOL
101
N
102
ONE
101
09
113
102
04
02
115
103
05
02
116
103
TERM
104
03
02
116
104
TERM
105
04
03
116
105
TERM
106
01
03
115
106
ONE
107
05
03
116
107
TERM
108
06
03
116
108
TERM
AGAIN
109
07
02
104
110
RESULT
RESULT
110
05
02
114
111
RESULT
111
10
114
STOP
112
00
DS
1
113
Symbol Table SYMBOL
ADDRESS
N
113
RESULT
DS
1
114
ONE
DC
‘1’
115
ONE
115
TERM
DS
1
116
TERM
116
AGAIN
104
RESULT
114
END
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Design of Two Pass Assembler PASS I Separate the symbol, mnemonic opcode,and operand fields. Build the symbol table Perform LC processing Construct intermediate code PASS II Synthesize the target code
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Required Data Structures for Two Pass Assembler Source Code Input PASS I
MOT Register Value Table Conditional Value Table Prerequisite Output
Intermediate Code Symbol Table Literal Table Pool Table
Input
PASS II
Output Machine Code
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Pass I INTERMEDIATE CODE
SOURCE PROGRAM
LOOP
(AD,01)
START
200
MOVER
AREG,
=‘5’
MOVEM
AREG,
A
MOVER
AREG,
A
MOVER
CREG,
B
ADD
CREG,
=‘1’
LTORG NEXT1
SUB
AREG,
ORIGIN
LOOP+1
MULT
CREG,
A
DS
2
BACK
EQU
LOOP
B
DC
1
END
‘=1’
(C,200)
200
(IS,04)
1
(L,01)
201
(IS,05)
1
(S,01)
202
(IS,04)
1
(S,01)
203
(IS,04)
3
(S,03)
204
(IS,01)
3
(L,02)
(AD,05) 205
005
206
001
207
(IS,02)
1
(AD,03)
(S,02)+(C,1)
203
(IS,03)
3
204
(DL,02)
(C,02)
(AD,04)
(S,02)
(DL,02)
(C,02)
B
206
(L,03) (S,03)
(AD,02) 207
001
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Pass I SOURCE PROGRAM
INTERMEDIATE CODE (AD,01)
(C,200)
START
200
MOVER
AREG,
=‘5’
200
(IS,04)
1
(L,01)
MOVEM
ADD,
A
201
(IS,05)
1
(S,01)
MOVER
AREG,
A
202
(IS,04)
1
(S,01)
MOVER
CREG,
B
203
(IS,04)
3
(S,03)
ADD
CREG,
=‘1’
204
(IS,01)
3
(L,02)
SUB
AREG,
‘=1’
ORIGIN
LOOP+1
MULT
CREG,
A
DS
1
BACK
EQU
LOOP
B
DS
1
LOOP
LTORG NEXT1
END
(AD,05) 205
005
206
001
207
(IS,02)
1
(AD,03)
(S,02)+(C,1)
203
(IS,03)
3
204
(DL,02)
(C,01)
(AD,04)
(S,02)
(DL,02)
(C,01)
B
205
(L,03) (S,03)
(AD,02) 206
001
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Pass I SYMBOL TABLE
INTERMEDIATE CODE (AD,01)
(C,200)
INDEX
SYMBOL
ADDRESS
LENGTH
200
(IS,04)
1
(L,01)
01
A
204
2
201
(IS,05)
1
(S,01)
02
LOOP
202
1
202
(IS,04)
1
(S,01)
03
B
205
1
203
(IS,04)
3
(S,03)
04
NEXT1
207
1
204
(IS,01)
3
(L,02)
05
BACK
202
1
(AD,05) 205
005
206
001
207
(IS,02)
1
(AD,03)
(S,02)+(C,1)
203
(IS,03)
3
204
(DL,02)
(C,02)
(AD,04)
(S,02)
(DL,02)
(C,02)
206
(L,03) (S,03)
INDEX
LITERAL
ADDRESS
01
=‘5’
205
02
=‘1’
206
03
=‘1’
207
POOL TABLE
(AD,02) 207
LITERAL TABLE
LIT_INDEX 001
#01 #03
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Examples Convert Source code into Pass I & Pass II
L1
START
100
MOVER
AREG,
=‘5’
ADD
CREG,
=‘1’
A
DS
3
MOVER
AREG,
B
ADD
AREG,
C
MOPVEM
AREG,
D
D
EQU
A+1
D
ORIGIN
A-1
SUB
AREG,
=‘1’
MULT
CREG,
B
C
DS
‘5’
ORIGIN
L2+1
LTORG L2
EXAMPLE 2 SIMPLE
LOOP
START
100
BALR
15,
0
USING
*,
15
L
R1,
TWO
A
R1,
FOUR
ST
R1,
FOUR
CLI
FOUR+3,
4
BNE
LOOP
BR
14
R1
EQU
1
TWO
DC
F’2’
FOUR
DS
F
END
STOP B END
DC
’19’
ASSUME:-BALR & BR are of two bytes…. L,A,ST,CLI,BNE are of four byte instructions…
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Intermediate Code Forms Variant I Variant II SOURCE PROGRAM
LOOP
VARIANT –I
VARIANT -II
START
200
(AD,01)
(C,200)
(AD,01)
(C,200)
READ
A
(IS,09)
(S,01)
(IS,09)
A
MOVER
AREG,
(IS,04)
1
(IS,04)
AREG,
A
AREG,
(L,01)
A
(S,01)
:
:
:
:
:
:
SUB
AREG,
=‘1’
(IS,02)
1
(L,01)
(IS,02)
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Pass II
INTERMEDIATE CODE (AD,01)
TARGET CODE
(C,200)
200
(IS,04)
1
(L,01)
201
(IS,05)
1
(S,01)
200
04
1
205
202
(IS,04)
1
(S,01)
201
05
1
204
203
(IS,04)
3
(S,03)
202
04
1
204
204
(IS,01)
3
(L,02)
203
04
3
205
204
01
3
206
(AD,05) 205
005
206
001
207
(IS,02)
1
(AD,03)
(S,02)+(C,1)
203
(IS,03)
3
204
(DL,02)
(C,02)
(AD,04)
(S,02)
(DL,02)
(C,02)
206
(L,03) (S,03)
005
206
001
207
02
1
207
203
03
3
205
204
(AD,02) 207
205
001 206
207
001
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
Assembler Examples
SOURCE PROGRAM
AGAIN
INTERMEDIATE CODE (AD,01)
(C,1000)
1000
(IS,09)
(S,01)
1001
(IS,04)
2
(L,01)
1002
(IS,05)
2
(S,02)
1003
(IS,03)
3
(S,02)
1004
(IS,05)
3
(S,02)
1005
(IS,01)
3
(L,01)
TERM
1006
(IS,05)
3
(S,02)
C,
N
1007
(IS,06)
3
(S,01)
BC
LE,
AGAIN
1008
(IS,07)
2
(S,03)
MOVEM
B,
RESULT
1009
(IS,05)
2
(S,04)
START
1000
READ
N
MOVER
B,
=‘1’
MOVEM
B,
TERM
MULT
B,
TERM
MOVER
C,
TERM
ADD
C,
=‘1’
MOVEM
C,
COMP
LTORG PRINT
RESULT
STOP
()AD,05) 1010
(L,01)
1011
(IS,10)
1012
(IS,00)
(S,04)
N
DS
1
1013
(DL,02)
(C,01)
RESULT
DS
20
1014
(DL,02)
(C,20)
TERM
DS
1
1034
(DL,02)
(C,01)
(AD,02)
END
Hope Foundation’s ,International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in
THANK YOU For Details feel free to contact Prof. Sameer Mamadapure sameerm@isquareit.edu.in Department of Information Technology Hope Foundation’s International Institute of Information Technology, P-14 Rajiv Gandhi Infotech Park, MIDC Phase I Hinjawadi, Pune – 411 057 Phone - +91 20 22933441 www.isquareit.edu.in | info@isquareit.edu.in