Pr.1)
“Systems Programming and Operating Systems”, by D.M. Dhamdhere,
Second Edition, Page No.106 (Exercise 4.4)
Problem
statement : Apply PassI of a two-pass Assembler to the following
assembly language code and generate Intermediate Code (IC), Symbol
Table, Literal Table and POOL Table according to IC VarientI.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Solution
: Following tables are used as input along with the above mentioned
assembly language code input to solve the problem. While implementing
in the laboratory, you can hard code these tables in any suitable
data structures.
OPTAB
Mnemonic
Opcode
|
Class
|
Code for
mnemonic
|
STOP
|
IS
|
00
|
ADD
|
IS
|
01
|
SUB
|
IS
|
02
|
MULT
|
IS
|
03
|
MOVER
|
IS
|
04
|
MOVEM
|
IS
|
05
|
COMP
|
IS
|
06
|
BC
|
IS
|
07
|
DIV
|
IS
|
08
|
READ
|
IS
|
09
|
PRINT
|
IS
|
10
|
START
|
AD
|
01
|
END
|
AD
|
02
|
ORIGIN
|
AD
|
03
|
EQU
|
AD
|
04
|
LTORG
|
AD
|
05
|
DC
|
DL
|
01
|
DS
|
DL
|
02
|
Registers
AREG
|
1
|
BREG
|
2
|
CREG
|
3
|
DREG
|
4
|
Condition
Codes
LT
|
1
|
LE
|
2
|
EQ
|
3
|
GT
|
4
|
GE
|
5
|
ANY
|
6
|
Solution
Intermediate
Code (IC)
Source
Code
(Input to
PassI of assembler)
|
Location
Counter
(LC)
|
Intermediate
Code (IC)
(Output of
PassI of assembler)
|
|||||
Label
|
Opcode
|
Operand1
|
Operand2
|
IC for
Opcode
|
IC for
Operand1
|
IC for
Operand2
|
|
START
|
100
|
(AD,01)
|
(C,100)
|
||||
A
|
DS
|
3
|
100
|
(DL,02)
|
(C,3)
|
||
L1
|
MOVER
|
AREG
|
B
|
103
|
(IS,04)
|
(1)
|
(S,03)
|
ADD
|
AREG
|
C
|
104
|
(IS,01)
|
(1)
|
(S,04)
|
|
MOVEM
|
AREG
|
D
|
105
|
(IS,05)
|
(1)
|
(S,05)
|
|
D
|
EQU
|
A+1
|
No IC,
Reflect in SYMTAB)
|
||||
L2
|
PRINT
|
D
|
106
|
(IS,10)
|
(S,05)
|
||
ORIGIN
|
A-1
|
(AD,03)
|
(S,01)-1
|
||||
C
|
DC
|
‘5’
|
99
|
(DL,01)
|
(C,5)
|
||
ORIGIN
|
L2+1
|
(AD,03)
|
(S,06)+1
|
||||
STOP
|
107
|
(IS,00)
|
|||||
B
|
DC
|
‘19’
|
108
|
(DL,01)
|
(C,19)
|
||
END
|
L1
|
(AD,02)
|
(S,03)
|
Symbol
Table (SYMTAB)
Symbol
|
Address
|
A
|
100
|
L1
|
103
|
B
|
108
|
C
|
99
|
D
|
101
|
L2
|
106
|
Literal
Table (LITTAB) and Pool Table (POOLTAB) : NIL (As no literals in the
source code)
No comments:
Post a Comment