
pdfaoa / CH11
.PDF
Procedures and Functions
11.14 Questions
1)Explain how the CALL and RET instructions operate.
2)What are the operands for the PROC assembler directive? What is their function?
3)Rewrite the following code using PROC and ENDP:
FillMem: |
moval, 0FFh |
FillLoop: |
mov[bx], al |
|
incbx |
|
loop FillLoop |
|
ret |
4)Modify your answer to problem (3) so that all affected registers are preserved by the FillMem procedure.
5)What happens if you fail to put a transfer of control instruction (such as a JMP or RET) immediately before the ENDP directive in a procedure?
6)How does the assembler determine if a CALL is near or far? How does it determine if a RET instruction is near or far?
7)How can you override the assembler’s default decision whether to use a near or far CALL or RET?
8)Is there ever a need for nested procedures in an assembly language program? If so, give an example.
9)Give an example of why you might want to nest a segment inside a procedure.
10)What is the difference between a function, and a procedure?
11)Why should subroutines preserve the registers that they modify?
12)What are the advantages and disadvantages of caller-preserved values and callee-pre- served values?
13)What are parameters?
14)How do the following parameter passing mechanisms work?
a)Pass by value
b)Pass by reference
c)Pass by value-returned
d)Pass by name
15)Where is the best place to pass parameters to a procedure?
16)List five different locations/methods for passing parameters to or from a procedure.
17)How are parameters that are passed on the stack accessed within a procedure?
18)What’s the best way to deallocate parameters passed on the stack when the procedure terminates execution?
19)Given the following Pascal procedure definition:
procedure PascalProc(i,j,k:integer);
Explain how you would access the parameters of an equivalent assembly language program, assuming that the procedure is a near procedure.
20)Repeat problem (19) assuming that the procedure is a far procedure.
21)What does the stack look like during the execution of the procedure in problem (19)? Problem (20)?
22)How does an assembly language procedure gain access to parameters passed in the code stream?
Page 635
Chapter 11
23)How does the 80x86 skip over parameters passed in the code stream and continue program execution beyond them when the procedure returns to the caller?
24)What is the advantage to passing parameters via a parameter block?
25)Where are function results typically returned?
26)What is a side effect?
27)Where are local (temporary) variables typically allocated?
28)How do you allocate local (temporary) variables within a procedure?
29)Assuming you have three parameters passed by value on the stack and 4 different local variables, what does the activation record look like after the local variables have been allocated (assume a near procedure and no registers other than BP have been pushed onto the stack).
30)What is recursion?
Page 636