Pages

Friday, November 15, 2019

Assembler Example1 ( Considering START and END directives)


Assembler Example1 (Considering START and END directives)




Pr.1) “Systems Programming and Operating Systems”, by D.M. Dhamdhere, Second Edition,Page No.91 (Fig. 4.5)

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.

START
101
READ
N
MOVER
BREG
ONE
MOVEM
BREG
TERM
AGAIN
MULT
BREG
TERM
MOVER
CREG
TERM
ADD
CREG
ONE
MOVEM
CREG
TERM
COMP
CREG
N
BC
LE
AGAIN
DIV
BREG
TWO
MOVEM
BREG
RESULT
PRINT
RESULT
STOP
N
DS
1
RESULT
DS
1
ONE
DC
‘1’
TERM
DS
1
TWO
DC
‘2’
END


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
101


(AD,01)
(C,101)


READ
N

101
(IS,09)
(S,01)


MOVER
BREG
ONE
102
(IS,04)
(2)
(S,02)

MOVEM
BREG
TERM
103
(IS,04)
(2)
(S,03)
AGAIN
MULT
BREG
TERM
104
(IS,03)
(2)
(S,03)

MOVER
CREG
TERM
105
(IS,04)
(3)
(S,03)

ADD
CREG
ONE
106
(IS,01)
(3)
(S,02)

MOVEM
CREG
TERM
107
(IS,05)
(3)
(S,03)

COMP
CREG
N
108
(IS,06)
(3)
(S,01)

BC
LE
AGAIN
109
(IS,07)
(2)
(S,04)

DIV
BREG
TWO
110
(IS,08)
(2)
(S,05)

MOVEM
BREG
RESULT
111
(IS,05)
(2)
(S,06)

PRINT
RESULT

112
(IS,10)
(S,06)


STOP


113
(IS,00)


N
DS
1

114
(DL,02)
(C,1)

RESULT
DS
1

115
(DL,02)
(C,1)

ONE
DC
‘1’

116
(DL,01)
(C,1)

TERM
DS
1

117
(DL,02)
(C,1)

TWO
DC
‘2’

118
(DL,01)
(C,2)


END









Symbol Table (SYMTAB)
Symbol
Address
N
114
ONE
116
TERM
117
AGAIN
104
TWO
118
RESULT
115

  



Literal Table (LITTAB) and Pool Table (POOLTAB) : NIL (As no literals in the source code)



No comments:

Post a Comment

ExampleMacroPassII