A typical accounting for the overhead might look like this:
instruction := Program[IP]
3
IP := IP+1
2
dest := abs(inst.) mod 1000
2
opnd2 := ...
2
opnd1 := ...
2
op := ...
2
sign := ...
2
if sign = '+' then
1
do case op of ...
1
TOTAL
17
(The exact number is not critical.)
Therefore the overhead is:
With software floating point: 17/117 = 15%.
With hardware floating point: 17/20 = 85%.
1-44:
Automation. Labeling would also be a good answer.
2-15:
By reference, M=2; by value-result, M=3.
2-16:
If the addresses are computed once, then the program prints 20, 11. If
they are computed on exit and the result is stored in I before a{A(I)}
is computed, then the program prints 10, 20. If they are computed on exit
and all addresses are computed before any results are stored, then the
program prints 20, 11.
2-28:
You can do it either for simple subscripts, A(I, J, K), or for subscripts
of the forms c*I+f.
In the former case, varying the first subscript changes the address by
1, varying the second changes it by l, and varying the third changes
it by lm.
In the latter case, the address changes for A(c*I+f, d*J+g,
e*K+h) are c,dl, elm.
2-30:
SYMTAB is 400 words long. In one subroutine, NM, WHERE, MODE, and SIZE
correspond to consecutive blocks of 100 words. In the second subroutine,
NAMES corresponds to the first 10 words. Therefore, LOC corresponds
to the next 100 words, that is, to NM(11) to NM(100) and WHERE(1) to WHERE(10).
And so forth.
3-1:
Here is a description of the diagram: Outer contour contains declarations
of i, j, P, and Q.
Contour for P contains declarations for x, y. Within P's contour is a contour
for an unnamed block declaring z. Within this contour are two more: one
declaring A and containing the statement "A[i] := j"; the other declaring
B.
Contour for Q contains declaration for x. Within this contour is invocation
P(n,i) and a contour for an unnamed block declaring n and R. Within this
is the contour for R, which declares a, b. Within the contour for R is
a contour for an unnamed block declaring x.
Also within the outermost (global) contour is a contour for an unnamed
block declaring i, k, and containing the invocation Q(0.0).
3-4:
Outer contour declares f, which points to a nested contour declaring x
and containing "x^2 + 1".
Within the outer contour is also a contour for Sum, which declares S and
X, and contains "S := S + f(x)".
3-9:
The "discr" procedure could be nested inside the "roots" procedure, thus
protecting the access of "roots" to "discr". However, if "discr" were also
used by another procedure, this wouldn't work unless the definition of
"discr" were also repeated in that other procedure.
3-16:
Assume the array is dimensioned "real array A [k1:u1, ..., kn:un]".
Let dn = 1 and dj = (uj - kj + 1)d(j-1), for 0 < j < n.
Then a{A[I1,...,In]} = a + Sum_{j=1}^n (Ij-kj)dj.
3-28:
for days := 31,
if mod(year,4) = 0 and (mod(year,100)
notequal 0 ormod(year,400) = 0) then 29 else
28,
31, 30, 31, 30, 31, 31, 30, 31, 30, 31 do ...
(Anything logically equivalent to this is correct.)
End of ch. 3-10:
a) 7, 7, 7, 2, 3, 3, 3, 2.
b) 7, 7, 7, 3, 3, 3, 3, 2.
c) 7, 13, 13, 2, 3, 3, 3, 2.
d) 11, 13, 13, 3, 3, 3, 3, 2.
4-9:
<id> ::= <letter> [<an string>] [_<an string>]*
<an string> ::= {<letter> | <digit>}+
(There are many other correct answers.)
End of ch. 4-2:
Arithmetic expressions. However, other nested structures such as
if-then-elses and compound statements are also examples.
End of ch. 4-3:
Here is a typical correct answer (there are many ways to write it):