Download SS-chapter-3-solution

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
QUESTION BANK
CHAPTER 3
ASSEMBLERS
2
Let us consider a two pass assembler and assume that each instruction isone word.
Given an assembly program and code for Mnemonics.
SYMBOL TABLE
No.
Symbol
Address
length
01
A
107
1
02
B
108
1
03
D
109
1
Mnemonic
START 101
READ A
READ B
MOVER BREG, A
MULT BREG, B
MOVEM BREG, D
STOP
A DS 1
B DS 1
D DS 1
END
(i)
Address Machine Code
101
102
103
104
105
106
107
108
109
09
09
04
03
05
00
0 107
0 108
2 107
2 108
2 109
0 000
VARIANT – I
(AD,01) (C,101)
(IS,09) (S,01)
(IS,09) (S,02)
(IS,04) (2)(S,01)
(IS,03) (2)(S,02)
(IS,05) (2)(S,03)
(IS,00)
(DL,02) (C,1)
(DL,02) (C,1)
(DL,02) (C,1)
Variant – II
(AD,01)
(C,101)
(IS,09)
A
(IS,09)
B
(IS,04)
BREG, A
(IS,03)
BREG, B
(IS,05)
BREG, D
(IS,00)
(DL,02)
(C,1)
(DL,02)
(C,1)
(DL,02)
(C,1)
(AD,02)
Show content of symbol table at the end of pass-one of an assembler.
07
(ii)
13
Write intermediate code representation of the assembly program. Use
Variant-II of intermediate code representation.
Consider following assembly program. Show (i) Contents of Symbol Table (ii)
intermediate codes using Variant I representation (iii) corresponding machine
codes
(Assuming Length = 1)
SYMBOL TABLE
No.
Symbol
Address
length
01
A
110
1
02
B
111
1
03
C
112
1
04
RESULT
113
1
Mnemonic
START 100
READ A
READ B
READ C
MOVER AREG, A
ADD AREG, B
ADD AREG, C
MULT AREG, C
MOVEM AREG, RESULT
PRINT RESULT
STOP
A DS 1
B DS 1
C DS 1
RESULT DS 1
END
Address Machine Code
100
101
102
103
104
105
106
107
108
109
110
111
112
113
09 0 110
09 0 111
09 0 112
04 1 110
01 1 11
01 1 112
03 1 112
05 1 113
10 0 113
00 0 000
VARIANT - I
(AD,01) (C,100)
(IS,09) (S,01)
(IS,09) (S,02)
(IS,09) (S,03)
(IS,04) (1)(S,01)
(IS,01) (1)(S,02)
(IS,01) (1)(S,03)
(IS,03) (1)(S,03)
(IS,05) (1)(S,04)
(IS,10) (S,04)
(IS,00)
(DL,02) (C,1)
(DL,02) (C,1)
(DL,02) (C,1)
(DL,02) (C,1)
Instruction opcodes:
READ – 09, MOVER – 04, MOVEM – 05, ADD – 01, MULT – 03, PRINT – 10,
STOP – 00
Assembler-directive codes: START – 01, END - 02
07
17
Register code: AREG – 01
Given an assembly language program for finding factorial of a given number N
with Mnemonic code details. Write an equivalent machinelanguage program.
07
ANSWER:
20
Given the source program:
07
SYMBOL TABLE
No.
Symbol
Address
01
A
02
L1
03
B
111
04
C
109
05
D
06
L2
length
100
1
1
1
07
MNEMONIC
START 100
A DS 3
L1 MOVER AREG,B
ADD AREG,C
MOVEM AREG,D
MOVER BREG,=’2’
MOVER CREG,=’4’
D EQU A+1
L2 PRINT D
LTROG
=’2’
=’4’
ORIGIN A-1
C DC 5
ORIGIN L2+3
STOP
B DC ‘19’
END L1
=’5’
ADDRESS
100
101
102
103
104
105
106
Variant – I
(AD,01) (C,100)
(DL,02) (S,01)
(IS,04)
(1)(S,02)
(IS,01)
(1)(S,04)
(IS,05)
(1)(S,05)
(IS,04)
(2)(L,01)
(IS,04)
(3)(L,02)
(AD,04) (S,01)
(IS,10)
(S,05)
(DL,05)
107
108
109
110
111
(AD,03)
(DL,01)
(AD,03)
(IS,00)
(DL,01)
(C,04)
(C,03)
112
1. Show the contents of symbol table at the end of pass I.
2. Explain the significance of EQU and ORIGIN statements in the program and
explain how they are processed by the assembler.
ANS 2. ) EQU Statement Defines Label D as A+1.
ORIGIN Statement starts Next Statement From Address of A -1.
3. Show the intermediate code generated from the program.
21
Given the source program:
07
(SAME AS 20th Question)
START 200
X DS 4
L1 MOVER AREG,Y
SUB AREG,Z
MOVEM AREG,W
W EQU X+2
L2 PRINT W
ORIGIN X-5
Z DC ‘9’
ORIGIN L2+1
STOP
Y DC ‘7’
END
1. Show the contents of symbol table at the end of pass I.
2. Explain the significance of EQU and ORIGIN statements in theprogram and
explain how they are processed by the assembler.
3. Show the intermediate code generated from the program.
25
Consider the following assembly program
START 500
READ N
MOVER CREG, ZERO
07
BK READ A
MOVER AREG, A
COMP AREG, MAX
BC LE, NT
MOVEM AREG, MAX
NT ADD CREG, ONE
COMP CREG, N
BC LT, BK
PRINT MAX
STOP
N DS 1
A DS 1
ZERO DC ‘0’
ONE DC ‘1’
MAX DC ‘0’
END
Instruction opcodes:
READ-09, MOVER-04,MOVEM-05, ADD-01,COMP-06, BC-07, PRINT-10,
STOP-00
Assembler directive codes: START 01, END-02
Register code: AREG-01, CREG-03
1. Identify task performed by above program.
2. Generate symbol table
29
3. Show intermediate code generated by above program
Given the following source program and code for mnemonics
1. Show the content of the symbol table at the end of pass-I of a two pass
assembler.
2. Show the intermediate code generated for program using variant-I of
intermediate code representation.
07
Assume that each instruction is one word.
SYMBOL TABLE
No.
Symbol
Address
01
A
02
L1
03
B
111
04
C
109
05
D
06
L2
07
100
length
1
1
1