Professional Documents
Culture Documents
Instructors Manual To Accompany Systems Programming by John J. Donovan PDF
Instructors Manual To Accompany Systems Programming by John J. Donovan PDF
Instructors Manual To Accompany Systems Programming by John J. Donovan PDF
SYSTEMS
'1FlOEFlAMMINE
dOtiN d. OONOVAN
SYSTEMS
'1flO~flAMMIN~
PROJECT MAC
~OVAN
MASSACHUSETTS INSTITUTE OF TECHNOLOGY
CAMBRIDGE. MASSACHUSETTS
07•017604-3
34567890WHWH0987654
\ \
TABLE OF CONTENTS
·1, I. PREFACE
1. One-semester sequence
2. Two-semester sequence
I. PREFACE
(d) Solutions.
The questions in the text have evolved over the six years
I have taught this course. We are pleased with the prob-
lems and feel that they not only test the students• knowl-
edge but also raise important issues. We have written
solutions to the problems that appear in the text. These
solutions are meant to be helpful to the instructor in
obtaining a viewpoint. We have expended a great deal of
effort in preparing questions and solutions, many of
which cover issues not dealt with in the text, e.g.,
problem 8.7 covers parsing of arithmetic statements. We
want to stress, however, that a small number of the ques-
tions may have more than one solution, depending on the
approach to this material. Our solutions may express a
different view than yours -- occasionally ours may be
wrong!
and most especially, the relevance of the material that make this
an exciting course.
We feel that the book has t~ree major uses: (1) as an under-
graduate text in a one- or two-semester course on systems pro-
gramming; (2) as a book for professional~: and (3) as a reference
for gradu.ate students.
More specifically, the book has been used to meet the needs
of the following types of courses:
Syllabuses
1/3 - homework
1/3 - quizzes
1/3 - final exam
1 Introduction; Preface;
overview of course Chapter 1
2 Machine structure 2.1 1 out
6 questions
3 Machine language 2.2-2.2.2 1 out
4 Machine language 2.2.3-2.2.4
5 Assembly language 2.3-2,4 1 due
2 out
6 Assembly language 3-3.2.3 1 first run
Assemblers
7 Assemblers 3.2.4-3.2.5
POSSIBLE SYLIABUSES -- AND USES 7
Prob Mach
Lecture Topic Readings Set Prob
Prob Mach
Lecture Topic Readings Set Prob
29 To be announced
30 I/0 progranuning 9-9.1.4 3 first run
31 Interrupt structure 9.1.5-9.1.7
32 Overview of 9.2 6 out
operating systems
33 Memory management 9.2
34 Processor management 9.3
35 File systems 9.5 6 due
36 Review 3 last run
16 Review
17 Quiz 1
18 High level languages Chapter 6 2 out
19 PL/I Chapter 6 4 out
20 PL/I examples
21 Formal systems; BNF 7-7.5
10 POSSIBLE SYLLABUSES -- AND USES
Prob Mach
Lecture Topic Readings Set Prob
Prob Mach
Lecture Topic Readings Set Prob
Prob Mach
Lecture Topic Readings Set Prob
Prob Mach
Lecture Topic Readings Set Prob
19 Quiz 1
20,21 High level langu- Chapter 6 4 out 2 out
22 ages, PL/I
23,24, Compilers Chapter 6
25
26,27, Compilers Chapter 6
28
29,30 I/0 programming 9-9.1.4 5 out
31
32,33, Operating systems; 9.2
34 memory management;
paging; segmentation
35,36 Processor management; 9.3
37 multiprocessing·;
deadly embrace
38,39, Information manage- 9.5 5 in 2 in
40 ment; file systems
41 Quiz 2
HELPFUL HINTS IN PRESENTING THIS MATERIAL 15
Many of the examples of the first few chapters use the 370.
The student should learn how to program the 370 or 360 in assembly
language. Most M.I.T. students taking this course do not have
a~y_assembly language programming background. Therefore, they
learn while taking this course. We use Chapter 2 as an introduc-
tion to assembly language and then assign a machine problem, such
as problem 15 of Chapter 2.
1) Section 1 (p3-5)
2) Section 2 (p7-18)
3) Section 3 (p19-21,
p23 up to "CSECT -- Identify Control Section",
p26 from "SYMBOLIC LINKAGES" through p 28)
4) Section 4 (p29-33)
5) Section 5 (p35-38 up to "Bit-Length Specification",
p40 from 0pera11d Subfield 4: Constant" through
11
If you choose to use PL/I and your students are not familiar
with it (as most of ours are not) we suggest assigning Chapter 6 and
problem to be programmed in PL/I. We usually have either several
in-class lectures on PL/I or else post-class seminars. Sometimes
Chapter 6 and a brief discussion of the differences between FORTRAN
and PL/I is all that is necessary.
You may point out to the students that the design procedure
outlined in section 3.1 [i.e., 1) statement or problem: 2) defini-
tion of data bases: 3) format of data bases: 4) algorithms: 5) modu-
larity] and followed for the design of assemblers in Chapter 3,
and again for the design of loaders in Chapter 5, was also followed
in the design of each phase of the compiler in Part 2.
Chapter 9 has also been divided into parts to make a very long,
complicated subject digestible.
The left side starts executing the main program. I draw on the
board a PSW, and CSW, and a CAW. They tell me how to modify it.
When the left side hits the SIO instruction, they start the right
side executing the I/0 program. Then both sides operate asyn-
chronously until the I/0 channel (right side) interrupts the CPU.
To simulate the interrupt, I have the I/0 channel student get up
and poke the appropriate CPU student.
(1) Memory
(2) Registers
15 index
4 common
16 accumulators
Floating:
Is I
35 34
exp fixed point
27 26 0
Is I
35 34 25 24
I
0 35 ~P.
Partial Fixed: (half, etc.)
20 HELPFUL HINTS IN PRESENTING THIS MATERIAL
I f j a u
op~ode
I
op code
'
~
--------- indirect
- address
index
modifier
\ modify
(partial word,
immediate) index
(which reg
A group)
control
register 0-16
within group
if H = 1, Xm +- Xm + Xi
[ after performing op code J
HELPFUL HINTS IN PRESENTING THIS MATERIAL 21
1108 CODE
Long Way
Location Instruction Assumption
Short Way
Location Instruction Assumption
General Procedures
Question Points
1 MACRO
2 DELTA &X
3 L l,&X
4 MEND
5 DELTA LOC
6 LOC DC F'lO'
7 END
Check the appropriate boxes in the table below. Should any of your
answers require qualification, footnote as necessary
EXAMPLE EXAMS AND EXTRA PROBLEMS 25
\I ; .
Source
Text
Object I
Code !
i
Symbol
Table
Literal
Table
Op
Table I
.
Pseudo-op
Table
Kitchen
Table I
Base -
Register
Table
Location
Counter
Perm- Create Alter Refer- Create Alter Refer-
anent ence ence
,,...._
.,.-., ,.~
'""-
-- - - -- - -- -
PAUL 390 --- -
-
- -- - -
Figure 2
2) Which phase puts the attributes for literals into the Literal
Table?
Which other phases add information to or delete information
from the Literal Table? Explain.
+ A B L l,A
* D Ml A l,B
·- C M2 ST l,Ml
L l,Ml
M O,D
ST l,M2
L l,M2
ST l,C
L l,A
A l,B
M 0,D
ST l,C
EXAMPLE EXAMS AND EXTRA PROBLEMS 29
Question 3
2) You are to devise a method for implementing the IF •.• THEN .••
statement given the following restrictions:
DEF L3
L3 EQU *
Machine Problem 1
Notes:
&A
ORG
SET.A
DC
DT RBL +&N
&M-& N
& A. C'.'
GRAOOOSO
GRA00060
GRA00070
!
H
MEND GRA00080 ~
MACRO GRA 00090 tu
&NAME GPRINT &ADDR,&LENGTH GRAOO 100 ~
G)
&NAME LA 3 ,&ADDR GRA 00110
LA
BAL
4, & L EN GT H
14,PRINT
****** DEST ROYS GR I S 1-4
******
GRAOO 120
GRA 001 JO i
MEND GRA00140
EJEC·T GRAOO 150
* PORTION OF THE PROGRAM 'rHAT IS I NV ARIANr EErW EEN PROBLEMS.
THIS SECTION PR3NTS OUT MESSAGES GIVING THE LOAD POINTS AND
GRA00160
* GRAOO 170
* THE NUMBER OF TRIALS THE STUDENT WILL GET.
SPACE 2
GRA 00180
GR AOO 190
ENTRY DUMPME GRA00200
G"RADER START 0 GRA00210
SA VE *
{ 14 , 12 ) , , GRA00220
BAL R EASE, 0 GRA.00230
USING *,BASE GRA00240
L BASE ,AG RAD EB MOVE BASE TO r HIS POINT GRA00250
USING GRADER,BASE GRA00260 w
w
w
~
GRA00270
* LR 11, 1 J GRA00280
LA 13,SAVEAREA GRA00290
ST 11, 4 ( 13) GRAOOJOl
ST 13,8(11) GRA 00310
MYC BUFFER,BUFFEB-1 BLANK OUTBUFFER INITIALLY GRA00320
GETPOOL PDCB,40,131 GRA00330
OPEN (PDCB, OUTPUT) GRA00340
GRA 00350
* GPRINT MESS1,L 1 MESS1 GRA00360
* SEE IF STUDENT IS THERE GRA00370
L 1, V STU DENT GET A DDR.E SS OF HI l1 GRA00380
LTB 1,1 SEE IF IT IS ZERO GRA00390
BNZ
GPRINT
R.
GOKIT
HOM FL USHIM
HE IS THERE
MESNOSTU,L'MESNOSra
GRA00400
GRA00410
GRAOO 420
~
tu
t-1
GOKI '!" UNPK HEX(?) ,AG RADER+ 1 ( 4) GBA00430 t:rJ
TR HEX(6),HEXTBL GBA00440
MVC MESS2B(6), HEX GRA00450 ~
UNP K HEX (7 J , VSTUDENT+ 1 (4) GRA00460 g
H
TR HEX ( 6) , EEXTBL GRA00470
MVC MESS3B (6) ,HEX GRA00480 ~
GPRINT MESS2A,MESS3D-MESS2A GRA00490 tu
.1.
STC
1,TES'l'NO
1,MESNO PUT IT IN MESSAGE
GET
NU11liER OF CALLS TO STUCENT GRAUU~UU
GllA00510
~
tJj
OI
B
MESNO,X 1 FO I
GRAGON
PLACE NUM.BER OF TESTS IN MESSAGE
GPRINT MESS4,M ESS4E-HESS4 TELL HOW MANY TRIA.LS
BRANCH ABOUND MESSAGES USED ONCE.
GRA00520
GRA00530
GRA00540
i
::,:,.
SPACE 2 GRA00550 ~
****** OUTPUT MESSAGES ****** GRA00560
Ci)
SPACE 2 GRA00570
MESS1
MESS2A
DC
DC
c•o
c•o
THIS IS THE
I AM LOADED AT •
6.251 MONITOR SPEAKING. HELLO. 1 GRA00580
GRA00590
!
H
MESS2B nc c•xxxxxx• GRA00600 z
Ci)
MESS2C DC C' (HEX) I GRA00610 tu
DC C', AND IOU ARE LOADED AT'
MESS3A
MESS3B oc c•xxxxxx•
GRA00620
GRA00630
~
MESS JC
MESS3D
DC
EQU
C'
*
( ll E X) • 1
*
*
THE STUDENT RETURNED WILL BE STORED 0-15 IN 1 STUBEG 1 •
REGISTERS EXCEPT 'BASE' WLLL BE AS THEY WERE WHEN THE STUDENT
ALL GR A00890
GRA00900
~
* Rh~URNED CONTROL. REGISTER 1 WILL HAVE BEEN STORED IN GRA00910
* LOCATION 1 STUANS 1 • IF YOU DO Nor NEED ANYrHING BUT 'STUANS', GRA 00920
* DO A i..M O, 15,PSAVEBEG, AND THINGS WILL BE AS THEY WERE BEFORE GRA009JO
* THE CALL TO STUOUT. YOU CAN THEN ANALYZE THE RESULTS. GRA00940
GRAC0950
* INTERNAL SU BRO UTI N ES A VAL !ABLE: GRA00960
* GRA 00970
** DUMP DUMPS STUDENT AREA USING 'STURE:.·• FOR REGISTERS. GRA00980
* PROBLEM- DESTBOUS MOST OF THE REGISTERS GRA00990
* DOftPKESS DUMPS STUDENT USING 1 STUREG 1 BUT WILL NOT GRAO 100:>
* HARM REGISTERS GRA01010
* DOMPME EXTERNAL ENTRY, DUMPS REGISTERS AS THEY GRA01020
w
• WERE ON ITS CALL GRAO 10 30 U1
w
(j'\
EJECT GRA010LIO
•••••• SPECIFIC SECT .ION OF PROGRUI
SPACE 2
•••••• GRAO 10 50
GRA01060
GBAGOH SB COUNT, COUNT GRAO 1070
LOOP LA COUNT, 1 ( 0, COUNT) GRAO 1080
BAL 14,NUMBER PRINT OUT TRIAL NUMBER GRAO 1090
LR COUNTX,COUNT GRA01100
SLL COUNTX, 3 GRAO 1110
LA COUNTX,TESTS-8(COUNTX) GRA O1120
ff V C H ES S 6 B + 1 ( 8) , 0 ( CO UN TX) GRAO 1130
GPRI NT MESS6 A, MESS Y-MESS6 A GRA O1140
LM 2, 3, 0 ( COUN TX) GRAO 1150
BA L 14 , STU O OT GO AND TRY STU DENT GRA01160
L.K O, 13, PS AVER EG GRAO 1170
UNPK HEX(9),STUANS(5)
rR
MVC
HEX(~,HEXTBL
ffESS10B,HEX
GRA01180
GRAO 1190
GRA01200
~
"'lj
t-t
t:i:j
GPBINT MESS 1 OA, MESS 11-M ESS1 OA GRAO 1210
LR
SLL
COUNTX,COUNT
COUNT.X, 2
GRA01220
GRAO 1230
~
()
LA COUNTX,TESTSA-4 (COUNTX) GRA 01240 ::c:
H
CLC STU ANS, O(COUNTX) GRA01250 zt:i:j
BNE WRONG GRA01260
"'lj
RIGHT GPRINT MESS11,L 1 MESS11 GRA01270
B TRY GRA01280 ~
a,
WRONG GPRINT I
MESS 12 , L MESS 1 2 GRA 01290 t-t
BAL 14, DUMPM ESS DUMP CORE ALL OVER THE PLACE GRA01300
~
TRY C COONT,TESTNO SEE IF DONE ALL TESrING GRA01310
BNE LOOP GRAO 1320 ~t1
HOM LA 13,SAVEAREA RECOVER ADDRESS IN CASE OF LOSS GR AO 13 30
L 13, 4 ( 13) GR AO 134:J Gl
RETURN ( 14, 12) , T . GRA01350 ~
SPACE 2 GRA01360 t1
H
MESS6 A DC c•o CONTENTS OF REGISTERS 2 AND 3 ••• • GRAO 1370 z
Gl
MESS6B DC c•••xxxxxxxx••• GRA01380
"'lj
ME.5S6C DC C' (EBCDIC). 1 GRA01390
~
MESSY EQU * END OF MESSAGE GRAO 1400 0
Gl
C1ESS10A DC C1 0 CONTENTS OF REGISTER 1 • • • 1 GRA01410
MESS 10 B nc c•xxxxxxxx• GRAO 14 20 ~
~
MESS10C DC C' (HEXADECIMAL). 1 GRA01430
~
tu
l1ESS 11 DC c•o CONGRATULATIONS, YOOR ANSWER IS CORRECT.' GRA01'J40 ~
M.8SS12 DC c•o SORRY, YOUR ANSWER IS INCORRECT.' GRAO 1450
******
EJECT
ROT INE TO PR INT TRIAL NUMBER
SPACE 2
******
GRA01460
GRA01470
GRA01480
!
H
zti:J
NUMBER ST 14,DM14 SAVE REGISTER 14 GRA Q1 ij9Q
STC COUNT, l1ESS5B GET COUNT INTO MESSAGE GBAO 1500 tu
MESS5D,X 1 F0 1 TURN IT INTO A CHARACTER
OI
GPRINT MESS 5A,M ESS5E-MESS5A
GRA 01510
GBAO 1520
~
to
L 14,DM14 GRA01530 tt
BR 14 RETURN GRAO 1540 ~
~PACE 2 GRA01550 ~
LA *
1 , 4 v: 8 4 0 ( 1 ) GRA 02810 ~
tIJ
ST 1, LAST STU GR A028 20
GPRINT
GPRINT SPACE,1
NOLAST,L'NO~AST GRA 02830
GRA02840
i
OK MVC
MVI
DUMPOUT(L 9 REG07) ,REGO?
EBCDUMF-1,X 9 5CV
GR AO 28 50
GRA02860
GRA02870
5
l'JVI EDCDUMP+32,X 0 5C 1 G)
LA
EAL
1, STU BEG
14, DUMPR
GRA02880
GR A 02890 ~
H
GR A02900
MVC
LA
DUMPOUT(LVREG81~ ,REG815
1,STUREG+8*4 GRAC2910 ~
BAL 1 4, DU l1 PR GRA029 20 l"CJ
GPRINT SPACE, 1 GRA 02930 ~
G)
MVC DUMPOUT(L' DUMP HD) ,DUMPHD GRA02940
GPRINT
MVC DUMPOUT (L REG815),DUMPOUTX
9
DUMPOUT,L 1 DUMPHD
BLANK BUFFER
GRA02950
GRAC2960
~
SR
B
COUNT,COUNT
DUMPLP+4
GRA02970
GRA 02980
;
ttJ
DU MPLP LA COUNT, 4*8(COUNT) GRA02990 ~
LR COUNTX,COUNT GRAO"JOOO
A COUNTX II STAR TAD GRAOJO 10 ~
(')
ST COUNTX,TEMP GRA03020 ~
UNPK H EX ( 7) , T EM P ( 5) GRAOJO 30 H
TR HEX (6) , HE XT BL GRA 03040
ztiJ
MVC AUS ( 6) , HEX GRA03050 ttJ
Lli
BAL
1 ,COUNTX
14, OUM PR
GBA03060
GBA03070
~
tJj
C COUNTX, LA,STSTU GRA03080 tt
BL DUMPLP GRA03090 I
GPRINT NOTE,L 0 NOTE TELL THEM ALL ABOUT IT GBA03100 ~
GPRINT Sl?ACE, 1 GRA03110 ~
L 14,DM14 GRAO 3120
G)
BR 14 GOH OM GR~ 031.30
SPACE 2 GRA031 llO ~
t:J
DUMPR ST 14,DREG GRA03150 H
MVC EBCDUMP(32) ,,0(1) MOVE INTO CHARACTER DUMP AREA GRAOJ 160
zG)
TR E BCD UMP (3 2) , DT R BL •
REPLACE ILLEGAL HEX ifITH C"a GRA03170 ttJ
LB CO UNTD1, 1 GRA 03180 ~
LA *
COUNT D ~, 4 8- 4 (CO UN TD 1) GRA03190
0
G)
~
L.t\ COUNTP1 ,HEXDUMP GRA03200
B DUMPRL +8 GRA03210
DUMPRL LA COUNTD1 ,4(COUNT01) GBA 03220
LA COUNTP1,10(COUNTP1) GRAOJ230
UNPK HEX(9) ,0(5,COUNTD1) GRAO 3240
Tf\ HEX(8),HEXTBL GRA 03250
l1V C 0 (8g COUNTP 1) , HEX GRAOJ260
CR COUNTD1 ,COUNTD2 GRA03270
BNE CUMPRL GRA03280
GPRI NT DUMPOOTX,L 9 DUMPOU?X GRA03290
L 14,DREG GRAO 330 0
BR 14 GRA03310
SPACE 2 GRA03320
GRA03330
****** DUMP PROGRAM MES SAGES
SPACE 2
****** GRA03l40
~
....,
~
N
MESS 13 DC c•o I AM DUMPING YOUR PORTION OF MEMORY.• GRA03350
REG07 DC CL14' REG. 0-7 1 GRA03360
REG815 DC CL 14 1 REG. 8- '15 1 GRA03370
DUMP HD DC CI ABS.• GRA03380
NOLAST DC C' 0 YOU DID_NOT SUPPLY AN ENTRY NA.MED 11 STDDENTN''•' GHA03390
NOTE DC c•o I CHOOSE TO PRINT ILLEGAL CHARACTERS AS PERIODS •• GRA03400
SPACE 2 GRA03410
****** TRANSLATE TABLE FOR EBCDIC DUMP ****** GRA03420
SPACE 2 GRA03430
DTRBL DC 256AL1 (*-DTRBL) SE1' FOR NULL TRANSLATION GRA03440
TDFN 0,64 GJU03450
TDFN 65 ,74 GRA 03460
T DFN 81, 90 GRA03470
TDF N 98,107 GBA03480
TDFN
TD F N
T DFN
112,122
12 8 , 1 9 3
202,209
GRA03490
GRA03500
GRAOJS 10
I
to
~
TDFN 218,226 GRA 03520 tzJ
T DFN
TDFN
234,240
250,256
GRA035JO
GRA 03540
~
()
EJECT GRA03550 Ill
H
****** INTERNAL GPRINT ROUTINE ****** GRA03560
~
SPACE 2 GRA03570
PRINT ST 1 4 1 SV 1 4 SAVE RET U RN GRA03580 to
BCTR 4,0 GBA03590 ~
IJj
EX 4,MOY E GBA03600 ~
PUT
MVC
PDCB,BDFPER
EUFFER, EU FFER-1
GRA 0361-0
GRA03620
I
L
BR
EJECT
14, SV 14
14
RESTORE B ETURN GBA03630
GBA 0.36110
GRA03650
i
****** CONSTANTS AND VARIABLE STORAGE
SPACE 2
****** GRA03660
GRA03670
~
t:,
H
1 STARTA0 1 IS THE ADDRESS THE DUMP PROGRAM STARTS AT. IF IT IS GRA03680 !2;
* NOT CHANGED Bl THE PROGRAM, ONLY rHE S?UDENT RPROGRAM WILL BE Cil
* DUMPED.
GRA 03690
IF IT IS DESIRED TO DUP A PART OF THE GRADING PROGRAM GRA03700 to
* * ~
* AS IN THE CASE WHERE THERE ARE SUBROUTINES SUPPLIED TO GRA03710
* THE STUDENT, THEN IT OUGHT TO BE CHANGED TO START SOMEWHERE GRA03720
I
ELSE. THIS CAN BE DONE EASILY GRA037 30
~
tu
* GRA03740
i:-t
l:%j
* GRA03750
STAB TAD
AG RADER
DC
DC
V (STUDENT)
A (G BADER) GRA03760 ~
(')
VSTU DENi'
DC V (STU DENT) GRA03770 l:I:
H
HEX DS CL10 GRAO 3780 zl:%j
MOVE !YC EU i,- PER ( 1 ) , 0 (3 ) GRA 03790
DC c• • GRA03800 tu
BUFF EB DS CL136 GRA C3810 ~
PSAVEREG DS 16F GRA038 20 tXI
t-t
SAVEAREA DS 18F GRA03830 l:%j
TEST NO DC F' 5 1 NUMBER OF TRIALS GRA03840 :3:
SPACE DC c•o• GRA03850 ~t,
DM14 DS F SPOT WHEREIN DUMP SAVES 14 GRAC3860
SY14 DS F SAVE REGISTER 14 UNIFORMLY GRA03870 Gl
'
SECOND DC F 1 100 1 GRAOJ880
S AVEBEG DS 16F GRA C3890 t,
H
STUREG DS 16F GRA03900 z
Gl
STOA NS DS F GRA 03910
LAST STU DS p GRA03920 tu
DREG DS F GRA03930 ~
TEMP DS F GRA03940 Gl
HEXTBLX
HEIT BL
DC
EQU
C 1 0123456789ABCDEF 1
HEIT BLX-C 1 0'
GRA 03950
GRA03960 ~
CL132 1
DOMPOUTX DC
DUMP OUT EQU DUMPOUTX+1
' GRA03970
GRA03980
AB.5 EQU DUMPOUT GRA03990
HEXDUMP EQU D UM POOT+ 11 PUT THE HEX HERE GilA04000
EBCDUMP EQU DUMPOUT+92 BUT PUT EBEDIC HERE GRAO 40 10
EJECT GRA040 20
****** TESTS CASES
SPACE 2
****** GRA 04030
GRA04040
TESTS DS OF GRA04050
DC CL8 1 AB, CDEFG'
DC CL8 1 A,BCD,EF 1
DC CL8 1 ABCDEFGH'
DC CL8 1 , , , , , , , , ' ~
w
DC CL8', A, D, C, D'
~
~
SPACE 4 GRA04110
TESTS A DS OF GRA 04120
DC F • 11
DC F1 2 1
DC F •o •
DC F'8'
DC F141
DC 4F 1 O• SPACE TO PREVENT DCB INTERFERENCE GRA04180
EJECT GRA04190
****** DCB ***** * GRA 04200
SPACE 2 GRA04210
P DCB D~B DSORG=PS,MACRF=PM,DEYD=DA,DDNAME=SYSPRINT,RECFM=FA,BLKSIZE=131 GRA04220
EJECT GRA 04230
******
.BASE
COUli.T
.RE GIST ER DEF.IN IT IONS
SPACE 2
EQU
EQU
12
5
****** GRA04240
GRA 042 50
GRA04260
GRA04270
;
1,:1
t"'
t::i:j
CODNTX EQU 6 GR A042 80
COUNTD1
COUNTD2
EQU
EQU
1
8
GRA04290
GRA 04300
~
COO NTP1 EQU 9 GRA04310
@
H
END GRADER GRA 04320
~
/*
1,:1
~
t,j
t"'
~
~
~
~
t:,
H
z
(j)
1,:1
I
//C EXEC PG M=AS MBLR, PARM= 1 NO DECK, LOAD'
~
tu
//SYSLIB DD DSN AM E=SY S 1. MACLIB, DISP=OLD t-t
l:%j
//SYSGO DD DSNA ME=&TE MP, DISP= (MOD, PASS), U NIT=SYS DA, X
II SPACE=(3000, (50,5)) ,DCB=(RECFM=FB,BLKSIZE=1600,LRECL=80) ~
()
//SYSUT1 DD DSNAME=&UT1 ,UNIT=SYSDA,SPACE= (3000, (50,25)) ::r:
//SYSUT2 DD DSN AME=& UT 2, UN IT=SY SDA, SPACE= (3000, ( 50, 2 5)} H
//SYSUT3 DD DS NA ME=6 UT 3, 0 NI T=SY SDA, SPACE= (3 000, (50 ,2 5)) ztij
//SY SPRINT DD SYSOUT=A tu
//SYSIN DD * B
STUDENT START 0 MP100010 tx:I
ENTRY STU DENTN MP100020 t-t
USING *,15 I
SR 1, 1 MP100030 ~
LM 4. S,=A(8, BACK) MP1000ti0 zt1
BACK STC 3,Y
(j)
S RDL 2, 8 MP100060
0 2,Y MP100070 ~
t1
EX 3, CLI MP100080 H
BNE BCTR MP100090 z
(j)
LA 1, 1 (, 1) MP100100 '"C1
BCTR 4,5 MP100110
~
BC1IR
BR 14 MP100120 (j)
Y
CLI
DC
CLI
STUDENTN EQU
F 10 1
Y,O
MP100130
MP100140
MP100150
i
END
* MP100160
I*
I IL EXEC PGM=IEWL,PARM= 1 NOLIST,NOMAP,NCAL',COND=(4,LT)
//SYSPRINT DD SYSOUT=A
//SYSLIN DD DSNAME=SI X251, UNIT= 1 CO I DTS P=OLD, VOLUME=S ER=CCSY DR
II DD DS NAM E=&TEMP, DISP= (OLD, DELETE)
//SYSLMOD DD DSNAHE=&LMOD(USERPROG) ,DISP= (NEW,PASS), X
II UNIT=SYSDA,SPACE= (3000, (100,50, 1))
//SYS UT 1 DD DSNAME=&UT1,UNIT=SYSDA,SPACE=(3000,(50,25))
/*
/IG EX EC PGM=*.L .SY SLKOD, COND= ( 4, LT)
//SYSLMOD DD DSNAME=&LMOD,DISP= (OLD, DELETE) ~
u,
//SYS PRINT DD SYSOUT=A
/'l;c
46 SOLUTIONS
VII. SOLUTIONS
CHAPTER 1: BACKGROUND
1. (processor, procedure)
A processor is a hardware device that interprets and executes
instructions; a procedure is a collection of instructions.
(procedure, program)
There is no difference between procedure and program.
(processor, I/0 channel)
An I/0 channel is a particular kind of processor, one which
interprets I/0 instructions.
(multiprocessing, multiprogramming)
In multiprog~amming, several programs are started before any
one has been executed to completion, regardless of the number
of processors; in multiprocessing, several processors work
simultaneously on the contents of a single common core memory,
regardless of the number of programs in the core.
(open subroutine, closed subroutine)
An open subroutine is an assembly (compile) time phenomenon in
which a block of code is inserted into the program; a closed
subroutine is at execution time, a separate block of code to
which control is transferred.
2. Any set of bits gains meaning only when it is used. The pro-
grammer in effect tells the processor how each group of bits is
to be interpreted. Once the processor starts execution, the
contents of the location counter are used to indicate the loca-
tion of the next instruction. The address field of the instruo-
tion may refer to a location that contains data. The same loca-
tion may be interpreted at one time as an instruction and at
another as data.
3. INPUT PROGRAM (BINARY DECK) OUTPUT
#1
B C A
I
,I E
#2
C
C E
~ F
#3
C A
~1
r
F G
G Square roots
#4 of Deck D
D ~I r. . - - -
48 CHAPTER I: BACKGROUND
4. a. Software f. Hardware
b. Hardware g. Software
c. Software h. Software*
d. Software L Software
e. Hardware j. Hardware
ii) The EXEC card for the next job step is encountered.
(The information on this card must be saved to be used
when its job step is executed.)
SOLUTIONS 49
g. RDR/INT:
INIT/TERM:
b. Data cards must be read and saved in the queue now, as they
will be physically inaccessible when the program is executed.
b-2) OPl = + 6
OP2 = - 1
OP3 = 12
OP3 > OPl > OP2
b. (1,393,741,824+348,435,456+174,217,728
+16,777,216+1,048,576+262,144+32,768
+4096+1024+512+256+32+16+8+4
= 1,934,220,800
c. + 5,914,973
d. C 1,1852(4,~
I0000 0011
0 7
111111:XX
000001:XX
b. SLL 1,1 will shift the register's contents left one place.
LA 1,0(1,1) will effectively add the register's contents to
itself and then add Oto the register.
10. No. Load, for instance, does neither since checking incurs
additional CPU time. The condition code is a record of the re-
sult of certain operations {e.g., subtract, test I/0, comparison)
that can later be used to determine the effect of a conditional
branch. It can save information about a number {+,-,0), about
the result of a logical operation, and the status of an I/0
process.
SOLUTIONS 55
MAR~ IR(addr)
IC ... IC+4
If no match, continue
to execute in sequence
~-E_v_en
_ ___,ta,,1 WR ._ R ( IR ( Reg 3 + 1) )
Comparand is
odd register
R or R +1
3 3
WR 4- R ( IR ( Reg 3 ) )
High
IC ._ IC+4
Continue if first
Equal operand greater than
comparand
Branch if first
IC 4- IR(addr) operand less than
or equal to comparand
58 CHAPTER 2: MACHINE LANGUAGE, MACHINE STRUCTURE,
ASSEMBLY IANGUAGE
12. a.
lo
1
2
MEMORY
.
CONTROLLER .
-- MAR .
.
- MBR N
14
LOCATION
,. ~ -
~
STACK
3
r ' l ll •• ~ I
CONTROLLER ,2
J •
. ,. 1
,,. "h..
- SP
INSTRUCTION - 0
~
INTERPRETER ~
f
INSTRUCTION 1_-
~
REGISTER
,I, ~
WORKING
REGISTERS
SOLUTIONS 59
b. ADD
c. LOAD
13. a. Contents of
Register 1 Register 2 Location A
3 5 ? 0
4 10 ? 0
5 10 7 0
6 10 14 0
7 24 14 0
8 23 14 0
9 23 14 23
b. 3) LM 1,2,B
4) AR 1,2
5) AR 1,1
6) SH l,=H'l'
7) ST l,A
8)
9)
STUDENT START 0
ENTRY STUDENTN
USING *,15
STM 2,3,DATA Store R2 and R3 in
data area
SR 1,1
LA 9,DATA These instructions
L 10,=F'l' initialize registers
L ll,=F 1 7 1 for the BXLE instruc-
tion
LOOP CLI 0(9),C'
BNE CHECK
A l,=F'l' increment Rl if
comparison true
CHECK BXLE 9,10,LOOP
BR 14
DATA DS 2F contents of R2 and
R3 put here
LTORG
STUDENTN EQU *
END
62 CHAPTER 3: ASSEMBLERS
CHAPTER 3: ASSEMBLERS
L l,ALL L l,ALL
A 1,TEN A 1,TEN
extra
ST l,TEMP
pass ~
L 1, JOHN L 2, JOHN
s 1,FOUR s 2,FOUR
A l,TEMP AR 1,2
Another feature is that if the extra pass were the first pass,
we could test for certain conditions. If the conditions were
not satisfied, the assembler would not assemble parts of the
program. For example, the user may wish to write a general
(but large) program for handling a wide range of data. If
he wishes to assemble the program for a smaller range of data,
he could place a parameter in his source code, which would be
tested and would result in assembling only the parts of the
program pertaining to the smaller range of data.
Lastly, an extra pass would use more computer time, making the
manufacturers very happy.
SOLUTIONS 63
3. a. 2
b. 1,2
c. 1
d. 1,2
e. 1
f. 2
g. 1,2
h. 1,2
i. 1,2
j . 2
k. 2
4. a. Yes.
b. Yes.
c. Yes, but each symbol must be defined by an EQU before it
is used, and any symbols in operand field must be defined
before it is encountered.
d. Same as (c) above.
e. Yes.
f. Yes, left up to the loader.
g. Yes.
h. Not at all. (Unless a special loader was designed that
could handle this in the loading process)
For pass 2, rather than just the eight bits of the op-code,
the machine-op table would also have to supply the four-bit
mask value, and to indicate the special case that all ex-
tended mnemonics represent.
9. a. SYMBOL TABLE
LITERAL TABLE
Empty
Contents
15 2
CODE
0 BALR 15,0
2 L 1,22(0,15)
6 A 1,22(0,15)
10 ST 1,26(0,15)
14 CLI 29(15),4
18 BC 7,0(0,15)
22 BCR 15,14
24 X'0002'
28-31 Reserved storage
66 CHAPTER 3: ASSEMBLERS
LITERAL TABLE
·[F'482' 640 4 R
Assembled Code
488 BALR 2,0
490 LM 1,6,106(3)
494 CR 2,1
496 BC 13,38(0,1)
500 LA 7,28(0,1)
504 CLI 44(1),X'90'
508 BCR 15,6
510 X'0040'
512 X'40'
513 X'40'
514 X'40
515 X'OOOO 0000 0000 0000'
523 Skipped for alignment
524 X'OOOO 0186'
528 X'OOOO 0186 1
'
532 X'OOOO 0186'
68 CHAPTER 3 : ASSEMBLERS
87 -9-6-67 95 95 95 95 95 95 95 95 95 95 ..
w
67 96 96 96 96 96 96 96 96 96 96 96 ):I
Cll
Cll
Pass Pass Pass Pass Pass Pass Pass Pass Pass Pass Pass
1 2 3 4 5 6 7 8 9 10 11
I
tt
t:i:J
~
Cll
(I)
0
04 04 04 04 04 t-'
c::
t-3
22 ~16 16 14 14 H
0
z
__.3.Yl6 22 ...2-2-" 14 16 16 (I)
32 ~14 22 22 22
-42-14 32 32 32 32
42 42 42 42 42
48 48 48 48 48
52 52 52 52 52
57 57 57 57 57
65 65 65 65 65
66 66 66 66 66
67 67 67 67 67
77 77 77 77 77
78 78 78 78 7S.
81 81 81 81 81
82 82 82 82 82
83 83 83 83 83
87 87 87 87 87
95 95 95 95 95
96 96 96 96 96
81 *48 *04 04 04 04
52 *52 *14 14 14 14
57 57 57 * *.A,8"' 4 2 *%16 16
22 22 22 22 22 22
95 *16 16 16 ~32 32
04 04 *48 *~~48 48 ~42
83 *14 *52 ~32 *42 *48
96 *77 77 *~.ftf5'65 *fi8"52 52
42 42 42 *57 57 57
32 32 32 *52 *65 65
48 *Bl ~ 66 **77 ~ 6 6 66 66
78 78 78 *)%'67 67 67
82 82 82 .~81 ~78 ~77
65 65 65 *77 77 *78
()
16 *95 *...9-5" 67 *78 *81 81 $1
tu
66 66 ~81 *82 82 82 t-3
t,cj
~
14 *83 83 83 83 83
w
77 *96 96 96 ~95 ~87
:r:,
87 87 87 87 87 95 CJ)
CJ)
1:2:j
67 67 *95 95 *96 96
~
t-t
Pass Pass Pass Pass Pass t,cj
~
1 2 3 4 5 CJ)
52 1) 81 52 1) 14,16 14
57 2) 52,22,42,32,82 22 2) 22 16
22 3) 83 42 3) 32 22
95 4) 04,14 32 4) 42,48 32
04 5) 95,65 82 5) 52,57 42
83 6) 96,16,66 83 6) 65,66,67 48
96 7) 57,77,87,67 04 7) 77,78 52
42 8) 48,78 14 8) 81,82,83,87 57
32 9) 95 9) 95,96 65
48 65 66
78 96 67
82 16 77
65 66 78
16 57 81
66 77 82
14 87 83
77 67 87
87 48 95
67 78 96
......
w
(1) b. -..J
~
~
'1::.1
t-3
1:1:1
~
..
w
~
CJ)
CJ)
I
ti
1:1:1
~
CJ)
Cll
0
t"'
~
H
,JU,4-413 413 180 180 180 0
zCfl
424 ~180 413 264 264
_.5.:7-3-- 18 0 424 ~264 413 413
573 -5,+3- 264 424 424 424
~264 573 573 573 573
616 616 616 616 616
679 679 679 679 679
709 709 709 709 709
807 807 807 807 807
882 882 882 882 882
887 887 887 887 887
975 975 975 975 975
. ...J
U1
...J
(2) b. O'\
!;
trj
r3
l:,:j
i:c,
..w
:x::,
Cl)
Cl)
I
t"f
l:,:j
i:c,
Cll
Cl)
( 3) b. 0
t"'
Cl
8
H
First Second Third
Distribution Merge Distribution Merge Distribution Merge
z0
Cl)
',,]
',,]
78 CHAPTER 3: ASSEMBLERS
14. 1) 4 probes
2) 3 probes
3) 4 II
4) 2 II
5) 4 II
6) 3 II
7) 4 II
8) 1 II
9) 4 II
10) 3 II
11) 4 II
12) 2 II
13) 4 II
14) 3 II
15) 4 II
15. a. C/l
0
tf
c::
Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 ~
H
~
\.0
CX)
0
Pass 1 Pass 2 Pass 3 Pass 4 Pass 5
()
Final ordering of table
~
t-c,
t-3
tTJ
::t:I
..w
:i:,
(/)
(/)
~
ll:I
t-t
tTJ
::t:I
Ul
CJ)
b. Pass 1 Pass 2 Pass 3 Pass 4 Pass 5 Pass 6 0
t"'
;J
100011 Tl 1"010000 T2 1(000100 T3 000100 T4 000100 TS 000100 T6 000100 T7,B7 H
ij
CJ)
011000 011000 ·kOOOlll B3 000111 B4 000111 BS 000111 B6 000111 T8,B8
111100 111100 T16 1c-lOOOll Tl 7 100011 T18 100011 Tl9 i:100001 T20, B20
100001 100001 100001 100001 Bl8 100001 B19 *100011 B21 ~100011 T23,B23
110111 110111 110111 T25 110111 T26 i:110000 T27 110000 T28 110000 T29,B29
110011 110011 110011 110011 110011 B27 110011 B28 110011 T30, B30
111001 Bll 111001 B16f 111001 B25/ 111001 B32 / 111100 T33,B33
(X)
j--1
82 CHAPTER 3 : ASSEMBLERS
16.
~
Radix
Shell Radix Interchange Exchange
A ,_
Examines all bits
(or characters) in key of
an item in each probe V ~
Requires large amounts
of extra storage ~
Requires only one pass
if table is already
V
sorted on entry to sort
--·-
Is a distributive sort
~
,,,
Requires items to be
sorted to be in binary
form
,,,,
17. This is dependent upon the limitations of the machine, such
as available core and the potential size of the symbol table.
Basically, the problem is that:
linear X
search
binary X
search
hash X
search
hash with
binary X
bucket
search
/ / / / / / / v / / / / / / / V / 1 / / / / I / / / I / / / I ~//1-7//)
sequential X
entry
sequential
entry with
interchange
sort
sequential
entry with
radix sort
sequential
entry with X
Shell sort
hash entry X
hash entry
with bucket X
sort
84 CHAPTER 3: ASSEMBLERS
DONOVAN- (4+6+5+6+4+1+5+0) = 13
MOD 19
MULHERN- (4+4+3+8+5+9+5+0)MOD = 0
19
FREYBERG (6+9+5+8+2+5+9+7)MOD = 13
19
MITCH--- (4+9+3+3+8+9+0+0)MOD = 8
19
HARRIS-- (8+1+9+9+9+2+0+0)MOD = 0
19
MARY---- (4+1+9+8+0+0+0+0)MOD = 3
19
MADNICK- (4+1+4+5+9+3+2+0)MOD = 9
19
NANGLE-- (5+1+5+7+3+5+0+0)MOD = 7
19
129
130 A
131 C
132 E
133
SOLUTIONS 85
ASHTON, BEN
BERMAN, HARRIS
BRUNK, GLEN
DODSON, ORVILLE
DONOVAN, CAROLYN
DONOVAN I MAUREEN
DONOVAN, JAMES
DONOVAN, REBECCA
DONOVAN I MARILYN
DONOVAN, JOHN
FREYBERG I DUTCH
GOODMAN, LEONARD
HAMMER, MICHAEL
JACK, MARTIN
JOHNSON, JERRY
KOHN, NORMAN
MADNICK, STUART
NANGLE, ELLEN
RAMCHANDANI, CHANDER
SINNOT, MARY
ZILLES, STEVEN
b. I = 6
1. The important thing here is that the input and output are text.
Except for macro instructions, such as MACRO, AIF, and MEND,
the actual characters are immaterial; thus, almost any format
could be accommodated.
1. XYZ &A
2. ST l,&A
3. MEND
4. MIT &Z
5. MACRO
6. &Z &W
7. AR 4,&W
8. XYZ ALL
9. MEND
10. ST &Z,ALL
11. MEND
12. HELLO &W
13. AR 4,&W
14. XYZ ALL
15. MEND
1. XYZ 1
2. MIT 4
3. HELLO 12
PROG START
USING *,15
ST 2,3
AR 4,YALE
ST l,ALL
YALE EQU 5
ALL DC F 3
1 1
END
88 CHAPTER 4: MACRO LANGUAGE AND THE MACRO PROCESSOR
1. EXPO &EXP
2. LCLA &N
3. &N SETA &EXP
4. AIF (&N EQ 1) .STOP
5. MR 0,2
6. &N SETA &N-1
7. EXPO &N
8. .STOP ANOP
9. MEND
1. EXPO 1
EX PON START 0
USING 0,15
L 2, BASE
L !,BASE
SR 0,0
MR 0,2
MR 0,2
ST !,ANS
BR 14
ANS DS F
BASE DC F 1S1
END
w
Must be built or modified in pass 1
Symbol table
Literal table
Collate tape
Pseudo-op table
Input deck
Location counter
Macro stack
90 CHAPTER 4: MACRO IANGUAGE AND THE MACRO PROCESSOR
The analog of the stack frame is the push down or LIFO (last-
in/first-out) stack, which contains intermediate values for
recursive routines, in particular, return addresses. This is
discussed further in section 8.4 -- Recursion.
5. a. No. The cards of the nested macro are stored in the MDT
as are all other cards in the external macro definition.
b. No.
MACRO
ADD &LAB,&LOC
. &LAB A l,&LOC
MEND
MACRO
ADD &IDC
LABEL A l,&LOC
MEND
does because the label will be inserted each time the macro
is called, resulting in a multiply-defined symbol. The macro
processor must generate a new symbol each time the·macro is
used.
8. a. (SR) MACRO
&LABl SR &0Pl,&OP2
&LABl SET LC
BYTE 1B(l6,8)
LC SET LC+l
BYTE &OP1(10,4),&0P2(10,4)
LC SET LC+l
MEND
92 CHAPTER 4: MACRO LANGUAGE AND THE MACRO PROCESSOR
MACRO
&LBL START &LOC
LC SET &LOC
&LBL SET LC
ORIGIN SET LC
BASE SET ¢
MEND
MACRO
&LBL USING &LOC,®
BASE SET ®
ORIGIN SET &LOC
&LBL SET LC
MEND
MACRO
&LBL A ®, &DATA, &INDEX
&LBL SET LC
BYTE 5A{16,8)
LC SET LC+l
BYTE ®{l0,4),&INDEX(l0,4)
LC SET LC+l
BYTE BASE{l0,4),&DATA/256-0RIGIN/
256(10,4)
LC SET LC+l
BYTE &DATA-ORIGIN{l0,8)
LC SET LC+l
MEND
For other op-codes, let us define the macro LOC for computing
and storing the offset and the base register.
MACRO
LOC &DATA
BYTE BASE(l0,4),&DATA/256-0RIGIN./
256(10,4)
LC SET LC+l
BYTE &DATA-ORIGIN{l0,8)
LC SET LC+l
MEND
94 CHAPTER 4: MACRO LANGUAGE AND THE MACRO PROCESSOR
MACRO
&LBL L ®,&DATA,&INDEX
&LBL SET LC
BYTE 58(16,8)
LC SET LC+l
BYTE ®(l0,4),&INDEX(l0,4)
LC SET LC+l
LOC &DATA
MEND
SOLUTIONS 95
2) LCLA and GBLA will change the definition phase but will
have no direct effect on the expansion phase.
0000 1BA4 5
0000 lBAB 2
c. Search the MST for the symbol in the label field of the
SETA statement. Then find the correct symbol by searching
the macro column as well.for the macro in which the SETA
occurred·. Then modify the location to which the value
pointer points to reflect the SETA statement. No differ-
ence between handling of local and global symbols.
96 CHAPTER 4: MACRO LANGUAGE AND THE MACRO PROCESSOR
Set up ALA
MDTP +- MDTP+l
Substitute arguments
from macro call
Write
expanded
source
card
Yes
No to "READ NEXT
SOURCE CARD"
Evaluate expressio
No
Set MDTP to
new value
98 CHAPTER 4: MACRO LANGUAGE AND THE MACRO PROCESSOR
Increment MDT
Get next card
pointer to next
from MDT
entry MDTP ~ MDTP+l
Substitute arguments
from macro call
TO "MDI = OFF"
Yes
Return to
main
processing
No
Evaluate expression
Set MDT to
new value
SOLUTIONS 99
CHAPTER 5: LOADERS
1. EXT RN SQRT
LABEL AR 5,2
LOOP B LABEL
END
a. A(LABEL) or A(LOOP)
b. A (LOOP-LABEL)
c. A (SQRT+LOOP)
5. ESD
TXT
RLD
END
8. a. PGA length: 16
PGAl offset: 8
PGB length: 20
PGBl offset: 0
PGB2 offset: 8
PGB3 offset: 16
PGC length: 16
PGCl offset: 4
PGC2 offset: 12
GEST
PGA 400
PGAl 408
PGB 416
PGBl 416
PGC 440
PGCl 444
PGC2 452
c. Location Contents
400 400
404 420
408 8
412 12
416 440
420 416
424 420
428 0
432 450
436 xxxx
440 12
444 440
448 452
452 448
456 xxxx
460 xxxx
9. a. Pass 1 scans all ESD cards to create the Global External
Table.
ENTl DS SD
instead of
ENTl DS SF
11. a. The ABS card should be first in the ·deck taking the place
of the START card. The location counter must be set to the
correct value to create an absolute symbol table.
12. a. Add one card type to the absolute loader, the R/A switch
card. A location internal to the loader will indicate
whether text is to be treated as absolute or relocatable;
this location will ~e set by the R/A switch cards:
SOLUTIONS 105
Relocatable text
Relocatable text
106 CHAPTER 5: I.DADE RS
ESD
f~ol
SOLN
A
Type
SD
ER
ID
01
02
Relative Address
0
Length
50
C2 ER 03
BALR 0
SR 2
SLL 4
TXT L 8
BR 12
DC 16 A(A+lO) 10
DC 20
DC 24 A(C2) 0
DC 28
DC 40
RLD rD02
03
Length
4
4
Flag(+/-)
+
+
Relative Address
16
24
ESD
l S~ol
GRADER
Type ID Relative Address Length
SD 01 0 60
C2 LD 24
BALR 0
SR 2
L 4
TXT ST 8
LA 12
L 16
BR 20
DC 24 A(GRADER) 0
DC 28
SOLUTIONS 107
NEW SD 01 0 188
STUDENT LD 0
ESD A LD 56
SOLN LD 72
DELTA ER 02
C2 LD 152
GRADER LD 128
DC 40 A (A+lO) 66
DC 56 A(DELTA) 0
TXT DC 64 A(-SOLN) -72
DC 88 A(A+lO) 66
DC 96 A(C2) 1~2
DC 152 A(GRADER) 128
108 CHAPTER 5: LOADERS
IN is needed.
b. See (a).
d. Same as (b).
If A= B THEN DO;
END;
ELSE GO TO LABEL;
A BEGIN block sets aside a block of code with the same effect
upon scope of variables as a procedure block, but which is
executed when encountered in the normal flow of control.
(1)
(2) X = .-2
y = -2
W =0
Z = 0
(8) M allocated
(9) M = 4
(10) Z = -4
(11)
(12)
1
(13) w = 2
( 14) ( 3)
(4)
1
(5) x = -4
(6) Z = 14
(15)
(16)
(19)
(20) X = 0
(21)
(22) z = 0
y = 0
w= 0
(23)
SOLUTIONS 113
8.
(1)
(2)
(3) Z = 12
(4)
(5)
(6) X = 5
(7) ZED= 17
(8)
(9)
(10) X = 1
{11)
(12)
{25) (37)
(38) Z = 1
{39) Z = -39
(40)
(41) {35)
(36) X = 5
{37)
(38) Z = 25
(39) Z = -15
(40)
{42) (26)
(27)
(28)
1
(29) Z allocated
{30) X = 4
1
(31) Z = 16
{32) X = 20
(33) z.1 freed
(43) (44)
(45)
{46) STR = 60
(47) Z = 80
{49)
114 CHAPTER 6: PROGRAMMING LANGUAGES
"
(sentence)
/
(clause) 6 (sentence)
/"
(clause) 0 (foo}
0 has precedence over 6
"'
(sentence)
(clause)~ (sentence)
/ / -~
(word } $ (cough)
/. "'
(clause) 6 (sentence)
SOLUTIONS 115
(word) "
/ $ (cough)
$ has precedence over 0
(clause)
/ \
(word) $ (cough)
/
(cough) A (char)
~
(clause)
I \
(word) $ (cough)
I \
(char) 0 . (char)
(cough)
"'
/
"'
(cough) A (char)
/
(char) D (char)
i) D > a
ii) $ > a
iii) $ > D
iv) 11 > $
v) 0 > $
vi) 0 > 11
d) (sentence)
I
(clause)
/ \ .
(w/ord) $ (cough)
/~
(c/ar) ;;9u~ A (chir)
A (char) 0 (char) D
I I
C D
A$C0DllD
2. 1) To specify a language
2) To recognize strings of a language
3) In investigating the complexity of a language
4) To show the possible equivalence of programs
5) To compare languages
i) (string expression)
~
(string expression)
I
(partial string)
11
"
(partial\string}
~ (basic i ! r i n ~
(nested string} (basiclstring} (letter}
I ~
(nested string)* (basic string)
A l
(basic.string)
A * BC - B II E = BCABC - B II E
= CAC II E
= CACE)
SOLUTIONS 119
~ ~ ~ested string)
(string expression} II (partial string)
A G I I
A 0
(nested str) (basic str)
r
(basic str} (basic str) (letter)
/
(basic str} (letter)
\ I \
(basic str} (letter} I
/
(basic str) (letter)
\ .
S
I I
A
I
T
(basi!'str~tte~S
I I
A o
. GH II osos - 0 * S II TI
120 CHAPTER 7: FORMAL SYSTEMS AND PROGRAMMING
LANGUAGES: AN INTRODUCTION
GH II osos - 0 * S II TI
= GH II osos - sos II TI
= GH 11 0 II TI)
= GHOTI
which is pronounced II
fish".
(GH as in LAUGH
0 as in WOMEN
TI as in COMMOTION)
b) * > - > II
c)
right
II *
operator
II < > >
(idn)
( l e t t ~ ~ g ~ d~git)(letter digit)
I
C
T
(letter)
T
(letter)
T
(letter)
I I I
0 S T
(idn) -
I I l
(idn)
I
2
I
(idn)
\* (I(exp))
\"
I I I / \~
START FINISH RATE (exp)(op)(exp)
I I / \~
(idn) - (exp)(op)(exp)
sTlRT (ikn) L (l~t)
FikisH 1bo
......
N
......
122 CHAPTER 7: FORMAL SYSTEMS AND PROGRAMMING
IANGUAGES : AN INTRODUCTION
ii) (stmnt)
(aJign)
/ \
(idn) = (exp)
I
COST
/\~
(exp)(op)(exp)
/I.\
(exp) (op) ( exp )
\ * \( (exp)
~)
Axp)(r(exp) ~ / 1
g (i:~ /x\p\\
I /I~
f I,~
(exp)(op)(exp) + (lit)
(idn)
I
* ((exp)) 2
I
(exp)(op)(exp)
I
(idn)
I I
- (idn)
- (lit)
I
100
I
RATE ;
. ·\ I
START I
FINISH
b. (procedure)
~I~
(idn): PROCEDURE ( (var))
/I
(stmnt) (body) END;
I
(WCM)
~
(idn) , {var)
/
(dcl)
I\
(stmnt )(body)
/
RATE
//1
(idn), (var)
I \
(assign)(stmnt)
I
START
I
(idn) SEE
I (return)
\
I ~!fT REJ~;
I
COST
"'
DECLARE (dcl element);
Ar ~
list) (attribute)
/I~
FIXED BINARY ( (lit)) STATIC
( (var) ) I
31
I"
(idn) (var)
I
COST I (var)
(idn) "
RATE
/ I "-
(idn} (var)
I I
START (idn)
I
FINISH
d. Eliminate:
Add:
b. Change:
5) q ~
6) t term
r qq ~
term
rt * q ~
Add:
10) p pritnary J- p ~
11) p primary s ~ ~ p $ s ~
9. a. (letter) :: = P IQ IR I S
(id) : : = (letter) I (id) (letter)
(primary) : : = (id) I ((exp))
(term) :: = (primary) I (term)* (primary)
(exp):: = (term) I (exp)+ (term)
b. No BNF equivalent
Canons not translatable: 5,6,7,8,9
QUESTIONS 7.10, 7.11, and 7.12 are left to the student as each
answer will be different.
SOLUTIONS 125
2. (translator, interpreter)
A translator inputs a program in one language and outputs a
program in another; an interpreter inputs a program in a
language and performs the intent of the program without pro-
ducing object code (e.g., the 370 is an interpreter for machine
code. Such languages as BASIC and APL are usually implemented
using an interpreter.
3. (pass, phase)
A pass is a physical traversal of the input deck or a data base;
a phase is a logical segment of a compiler, performing one con-
conceptual function (e.g., the optimization phase may consist
of many passes, where the two phases, syntax and interpretation,
may be implemented as. a single pass.
6. The idea is that each phase performs some unique function that
can be understood more easily as a separate unit. A compiler,
for instance, could be considered as a one-phase program, the
compile phase. But this doesn't say anything about its con-
struction. Neither does the idea of a 11 matrix-generation 11
phase say enough to someone trying to understand (or design)
the compiler.
Terminal Table X X X
Identifier Table X X X
Literal Table X X X
Reductions X X X
Uniform Symbols X X X
Matrix X X X
Matrix Operators X X X
Code Productions X X X
Action Routines X X X
tin reality, many of these data bases may depend slightly on the
machine or their formats and contents are partially influenced
by the machine.
SOLUTIONS 127
11. Change the code productions and the assembler phase to produce
645 code.
A(l) (
(length of A frame)~(50-l)
A(2) (
location of C
A(50) l f?~~ ~ - -
V
..L
•
128 CHAPTER 8: COMPILERS
procbgn (idn)
DCL does not directly result in any entry in the matrix. When
processing the DCL statement, the interpretation phase simply
places the appropriate information into the identifier table.
Later, however, the storage assignment phase must assure that
the storage will be assigned, and if the initial attribute was
used, the storage must be initialized accordingly. To accom-
plish this, when scanning through the identifier table, the
storage phase will generate appropriate matrix entries for code
generation to have the storage assigned and initialized.
18. The code generation patterns for (+) serve as a model as ade-
quately as one that could be given here for (-).
21. a. ·y X
X
X X
X X
22. There are two cases here -- one involving the unary operator•{-)
and one the binary operator {-).
Case 1: - (A-B) + X
B-A + X
- B A - A B
+ Ml X - 0 Ml * See note on
+ M2 X following page
Case 2: X - (A - B)
X + B - A
+
- Ml
X B
~
~
A
130 CHAPTER 8: COMPILERS
2 4. 1) a. LITERAL TABLE
10 BINARY FlXED 15 0
IDENTIFIER TABLE
Storage
Scale Precision Class Address
After l
Lexical!
Phase~,I
I
: ,,,.. After Interpretation Phase . I
I
: ....4.___ _ _ After Storage Assignment Phase - - - - - - -........ I
I
132 CHAPTER 8: COMPILERS
b.
END
PROCEDURE
l* 18 8
2* 19* 9
4* 7 10*
4 8
5* 9*
7* 12*
14 7
15* 8
15 9*
16* 12*
14* 7
d. Matrix
1) procbhn BEGIN
2) arg A
3) arg B
4) = A 10
5) = B A
6) procend
BEGIN START 0
STM
BALR
USING
15,13,SAVE
15,0
*,15
} 1
ENTRY A } 2
ENTRY B } 3
LH
STH
l,=H'lO'
l,A
} 4
LH
STH
1,A
l,B
} 5
LM 15,13,SAVE
BR 15 } 6
A DS H from
B
SAVE
DS
DS
LTORG
H
15F J} storage
assignment
6
END
2) a. LITERAL TABLE
10 BINARY FIXED 15 0
~ - - - - - A f t e r Lexical Phase~-------11...
..,.__ _ _ _ _ After Storage Assignment Phase _ _ _ __.,.,__
IDENTIFIER TABLE
Storage
Name Base Scale Precision Class Address
After
Lexical
Phase
b.
END
PROCEDURE
SOLUTIONS 135
l* 18* 7
2* 14* 8*
4* 18 5*
4 19* 7
4 7 8
5* 8 9
7* 9* 10*
14 12*
15* 7
15 8
16* 9*
14* 12*
d. Matrix
1) procbgn MIT
2) arg JOHN
3) arg STU
4) arg BILL
5) * STU BILL
6) = JOHN MS
7) * BILL 10
8) - JOHN M7
9) = STU MB
10) rtn
11) arg STU
12) procend
ENTRY JOHN } 2
ENTRY STU } 3
ENTRY BILL } 4
LH !,BILL
SR
M
ST
0,0
O,STU
l,MS
} 5
L l,M5
ST !,JOHN } 6
LH l,=H'lO'
SR
MH
ST
0,0
0,BILL
l,M7
} 7
}
L !,JOHN
s l,M7 8
ST l,M8
l,M8
L
ST l,STU } 9
LA 14,STU } 10,11
LM 15,13,SAVE
BR 15 } 12
JOHN DS F
STU DS F
BILL DS H from
MS DS F storage
M7 DS F assignment
MB DS F
SAVE DS lSF
LTORG
END
} 12
D017I/ = /1/,/10/,/1
The syntactic phase, on encountering an incorrect structure
would return to the lexical phase rather than immediately
taking error action. The lexical phase would then parse
under different rules to produce
D0/17/I/ = /1/,/10/,/1
27. a. No parenthesesization
ENTER
. ,
INCREMENT INDEX
BY ONE
.,
PAST END OF
EXPRESSION?
~~-0
----v;::;)
IS '!OKEN AN NO _
i--~~~~~.P.....~~~~-
0 PE RA TOR?
YES
REPLACE WITH
A MATRIX REFERENCE
OF FORM Mi
SOLUTIONS 139
b. (idn) = //***/
1 (any) (op) (idn) /mat_ent/*/
(any) ; ///2
//*/1
2 (idn) = (any) ; /assign/"/
+ (any) (idn)
Or - (any) (idn)
= (ian) (any)
33. No. This will handle all the variables, but for program
control (like renumbering the number of levels of recursion),
a stack frame is needed (check the PL/I RECURSIVE attribute).
DCD 1A STATIC,
2B,
3A CHAR(4);
DCL lA STATIC
2A CHAR (4),
2A CHAR(4),
b. Reduction #
Sa) DO; /do/ 11 **/7
Sb) DO (idn)/iterative/"**/21
~ f A.B.NEXT within
A array.
~ o f C within
A data structure
2. When the CPU has only such primitive I/0 functions, it has to:
b. READ, WRITE, SKIP, READ CARD READER (RCR), TEST, ••• , etc.
d. Most I/0 routines are very similar. The use of system macros
takes the programming load from the progranuner.
146 CHAPTER 9: OPERATING SYSTEMS
6. Overall strategy is to make the 360 behave like the 370. The
370 would not give a program interrupt on an instruction
A 1, 1317 since the 370 does not require full word allignment
for its full word data accesses. (Note: On the 370, word allign-
ment is encouraged, for there is a high penalty for odd boundary
accesses, e-. g. , ten times slower) •
The symbol table, code, and matrix are all impure. If you
consider an assembler (or compiler) being used in -a multipro-
grammed environment processing several source programs
"simultaneously" it obviously cannot use any of these for all
programs being processed.
9. Page
Pure procedures are useful when more than one user is likely
to be using the procedure at the same time and when re-entrant
properties are desired. A third advantage of pure procedures
is that they are read-only? Thus a paging environment need not
write out overlayed pages.
Advantages: 1) sharing
2) facitates recursion
3) read-only
12. In the order given, both the flexibility of address space allo-
cation and cost in terms of complexity and overhead increase.
15. a.
I/0 COMPLETED
PAGE
EXECUTION FAULT
RESUMED
PAGE I.OADED
OTHER
STATES
PROCESS
COMPLETE
REAL-TIME PROCESS
INTERRUPT COMPLETE
EXEC UT I
RESUME
152 CHAPTER 9: OPERATING SYSTEMS
16. Races occur when two or more processes need the same device
at the "same time". (See section 9.3.3). They can be re-
solved by making it standard practice to request devices and
release them when done.
19. The I/0 traffic controller makes sure that an I/0 device is
used by one process at a time, and can maintain a queue of those
waiting to use a device, should several processes request it
while it is unavailable.
21. OPEN causes information (about a file that will be used fre-
quently) to be copied into core. This--information includes
the format and location of the file to be read. If the file
is to be accessed frequently, i t is best not to have to access
the information about the file, which is also stored on secondary
storage everytime.
23. a. Yes. This simple computer only affects the actual I/0
mechanism, not the logical file organization.
i +- 1
write
card (i)
character
{call IOCS)
yes
finished
154 CHAPTER 9: OPERATING SYSTEMS
2) Paging: Disc
Drum
File system
Core
Tape
DBR
Relocation register
d. File system
PBR
DBR
Relocation register
29. a. The 360 has its base register facility as an aid to imple-
menting pure procedures. It also has protect~on on blocks
of core memory.
d. The linkage segment of SQRT must load the LP with the proper
value.
The CPU's location counter has the segment number and word
number (e.g., <32,177>). But the segment number (e.g., 32)
could correspond to any place in the new address space unless
SWAP_DBR had the same segment number (e.g., 32) in all address
spaces.