V4Questions.pdf

(1404 KB) Pobierz
AoA.book
Questions, Projects, and Laboratory Exercises
Questions,
Projects, and Labs
Chapter Thirteen
13.1
Questions
1)
What is the purpose of the UNPROTECTED section in a TRY..ENDTRY statement?
2)
Once a TRY..ENDTRY statement has handled an exception, how can it tell the system to let a nesting
TRY..ENDTRY statement also handle that (same) exception?
3)
What is the difference between static and dynamic nesting (e.g., with respect to the TRY..ENDTRY state-
ment)?
4)
How you can you handle any exception that occurs without having to write an explicit EXCEPTION han-
dler for each possible exception?
5)
What HLA high level statement could you use immediately return from a procedure without jumping to
the end of the procedure’s body?
6)
What is the difference between the CONTINUE and BREAK statements?
7)
Explain how you could use the EXIT statement to break out of two nested loops (from inside the inner-
most loop). Provide an example.
8)
The EXIT statement translates into a single 80x86 machine instruction. What is that instruction?
9)
What is the algorithm for converting a conditional jump instruction to its opposite form?
10)
Discuss how you could use the JF instruction and a label to simulate an HLA IF..ENDIF statement and a
WHILE loop.
11)
Which form requires the most instructions: complete boolean evaluation or short circuit evaluation?
12)
Translate the following C/C++ statements into “pure” assembly language and complete boolean evalua-
tion:
a) if( (eax >= 0) && (ebx < eax ) || (ebx < 0 )) ebx = ebx + 2;
b) while( (ebx != 0) && ( *ebx != 0)) { *ebx = ‘a’; ++ebx; }
c) if( al == ‘c’ || al == ‘d’ || bl == al ) al = ‘a’;
d) if( al >= ‘a’ && al <= ‘z’ ) al = al & 0x5f;
13)
Repeat question (12) using short circuit boolean evaluation.
14)
Convert the following Pascal CASE statement to assembly language:
CASE I OF
0: I := 5;
1: J := J+1;
2: K := I+J;
3: K := I-J;
Otherwise I := 0;
END;
15)
Which implementation method for the CASE statement (jump table or IF form) produces the least amount
of code (including the jump table, if used) for the following Pascal CASE statements?
a)
CASE I OF
0:stmt;
100:stmt;
1000:stmt;
END;
Beta Draft - Do not distribute
© 2001, By Randall Hyde
Page
1195
286681600.001.png
Chapter Thirteen
Volume Four
b)
CASE I OF
0:stmt;
1:stmt;
2:stmt;
3:stmt;
4:stmt;
END;
16)
For question (15), which form produces the fastest code?
17)
Implement the CASE statements in problem three using 80x86 assembly language.
18)
What three components compose a loop?
19)
What is the major difference between the WHILE, REPEAT..UNTIL, and FOREVER..ENDFOR loops?
20)
What is a loop control variable?
21)
Convert the following C/C++ WHILE loops to pure assembly language: (Note: don’t optimize these
loops, stick exactly to the WHILE loop format)
a)
I = 0;
while (I < 100)
I = I + 1;
b)
CH = ‘ ‘;
while (CH <> ‘.’)
{
CH := getch();
putch(CH);
}
22)
Convert the following Pascal REPEAT..UNTIL loops into pure assembly language: (Stick exactly to the
REPEAT..UNTIL loop format)
a)
I := 0;
REPEAT
I := I + 1;
UNTIL I >= 100;
b)
REPEAT
CH := GETC;
PUTC(CH);
UNTIL CH = ‘.’;
23)
What are the differences, if any, between the loops in problems (21) and (22)? Do they perform the same
operations? Which versions are most efficient?
24)
By simply adding a JMP instruction, convert the two loops in problem (21) into REPEAT..UNTIL loops.
25)
By simply adding a JMP instruction, convert the two loops in problem (22) to WHILE loops.
26)
Convert the following C/C++ FOR loops into pure assembly language (Note: feel free to use any of the
routines provided in the HLA Standard Library package):
a)
for( i = 0; i < 100; ++i ) cout << “i = “ << i << endl;
Page
1196
© 2001, By Randall Hyde
Beta Draft - Do not distribute
Questions, Projects, and Laboratory Exercises
b)
for( i = 0; i < 8; ++i )
for( j = 0; j < 8; ++j )
k = k * (i - j);
c)
for( k= 255; k >= 16; --k )
A [k] :=
A[240-k]-k;
27)
How does moving the loop termination test to the end of the loop improve the performance of that loop?
28)
What is a loop invariant computation?
29)
How does executing a loop backwards improve the performance of the loop?
30)
What does unraveling a loop mean?
31)
How does unraveling a loop improve the loop’s performance?
32)
Give an example of a loop that cannot be unraveled.
33)
Give an example of a loop that can be but shouldn’t be unraveled.
34)
What is the difference between unstructured and destructured code?
35)
What is the principle difference between a state machine and a SWITCH statement?
36)
What is the effect of the NODISPLAY procedure option?
37)
What is the effect of the NOFRAME procedure option?
38)
What is the effect of the NOSTKALIGN procedure option?
39)
Why don’t you normally use the RET instruction in a procedure that does not have the NOFRAME
option?
40)
What does the operand to the RET(n) instruction specify?
41)
What is an activation record?
42)
What part of the activation record does the
caller
construct?
43)
What part of the activation record does the
callee
(the procedure) construct?
44)
Provide a generic definition for “The Standard Entry Sequence.”
45)
What four instructions are typically found in an HLA Standard Entry Sequence?
46)
Which instruction in the Standard Entry Sequence will HLA
not
generate if you specify the NOALIGN-
STK option in the procedure?
47)
Which instruction is the Standard Entry Sequence is optional if there are no automatic variables?
48)
Provide a generic definition for “The Standard Exit Sequence.”
49)
What three instructions are typically found in an HLA Standard Exit Sequence?
50)
What data in the activation record is probably being accessed by an address of the form “[ebp-16]”?
51)
What data in the activation record is probably being accessed by an address of the form “[ebp+16]”?
52)
What does the
_vars_
constant tell you?
53)
What is the big advantage to using automatic variables in a procedure?
54)
What is the difference between pass by reference parameters and pass by value parameters?
55)
Name three different places
where
you can pass parameters.
56)
Which parameter passing mechanism uses pointers?
Beta Draft - Do not distribute
© 2001, By Randall Hyde
Page
1197
Chapter Thirteen
Volume Four
57)
For each of the following procedure prototypes and corresponding high level syntax procedure calls, pro-
vide an equivalent sequence of low-level assembly language statements. Assume all variables are
int32
objects unless otherwise specified. If the procedure call is illegal, simply state that fact and don’t attempt
to write any code for the call. Assume that you are passing all parameters on the stack.
a) procedure proc1( i:int32 ); forward;
a1) proc1( 10 );
a2) proc1( j );
a3) proc1( eax );
a4) proc1( [eax] );
b) procedure proc2( var v:int32 ); forward;
b1) proc2( 10 );
b2) proc2( j );
b3) proc2( eax );
b4) proc2( [eax] );
58)
When passing parameters in the code stream, where do you find the pointer to the parameter data?
59)
When passing parameter data immediately after a CALL instruction, how do you prevent the procedure
call from attempting to execute the parameter data upon immediate return from the procedure?
60)
Draw a picture of the activation record for each of the following procedure fragments. Be sure to label the
size of each item in the activation record.
a)
procedure P1( val i:int16; var j:int16 ); nodisplay;
var
c:char;
k:uns32;
w:word;
begin P1;
.
.
.
end P1;
b)
procedure P2( r:real64; val b:boolean; var c:char ); nodisplay;
begin P2;
.
.
.
end P2;
c)
procedure P3; nodisplay;
var
i:uns32;
j:char;
k:boolean;
w:word;
r:real64;
Page
1198
© 2001, By Randall Hyde
Beta Draft - Do not distribute
Questions, Projects, and Laboratory Exercises
begin P3;
.
.
.
end P3;
61)
Fill in the pseudo-code (in comments) for the following procedures:
a)
procedure P4( val v:uns32 ); nodisplay;
var
w:dword;
begin P4;
// w = v;
// print w;
end P4;
b)
procedure P5( var v:uns32 ); nodisplay;
var
w:dword;
begin P5;
// w = v;
// print w;
end P5;
62)
Given the procedures defined in question (61) above, provide the low-level code for each of the following
(pseudo-code) calls to P4 and P5. You may assume that you can use any registers you need for temporary
calculations. You may also assume that all variables are
uns32
objects.
a) P4( i );
b) P4( 10 );
c) P4( eax+10 );
d) P5( i );
e) P5( i[ eax*4 ] );
f) P5( [eax+ebx*4] );
63)
This question also uses the procedure declarations for P4 and P5 in question (61). Write the low-level
code for the statements in the P6 procedure below:
procedure p6( val v:uns32; var r:uns32 ); nodisplay;
begin P6;
P4( v );
P4( r );
P5( v );
P5( r );
end P6;
64)
Describe the HLA hybrid parameter passing syntax and explain why you might want to use it over the
low-level and high-level procedure call syntax provided by HLA.
Beta Draft - Do not distribute
© 2001, By Randall Hyde
Page
1199
Zgłoś jeśli naruszono regulamin