Date: Tue, 14 Jan 1997 23:19:27 GMT Server: NCSA/1.5 Content-type: text/html Homework 9

Computer Organization and Assembly Language Programming

22C:18/108

Homework 9: Due 4/24/95

Problem 1: [9 points]

Translate the following recursive Pascal function into a recursive MC68000 subroutine. As you already know, this function computes for any integer and any positive integer .

Then calculate the size of the stack frame for each call (you need not use the link and unlk instructions.) Suppose you were running your program on a machine with stack size bounded above by 16K. What is the maximum value of n for which your program would be able to calculate power(m,n)?

Problem 2: [8 points]

Suppose that the above subroutine is called from the main program with two addresses (each 32-bits), say ad1 and ad2, passed as parameters via the run-time stack.

(a)
Show the run-time stack just after the subroutine mystery has been called from the main program. Label each item in the stack and specify its size in bytes.
(b)
Show the run-time stack just after the first movem.l instruction in mystery has been executed. Label each item in the stack and specify its size in bytes.
(c)
Show the run-time stack just after the rts instruction in mystery has been executed. Label each item in the stack and specify its size in bytes.
(d)
Describe precisely what the above subroutine does.

Problem 3: [8 points]

Given above is a recursive subroutine called strange. Two parameters, a 16-bit non-negative integer, say N, and a 32-bit address, say A, are passed to the subroutine via the run-time stack. As you might notice, the subroutine strange returns a 16-bit answer in (D0.W).

(a)
Draw the run-time stack showing one stack frame clearly. Label all items in the stack frame and specify their sizes.

(b)
Suppose that the main program that calls the above subroutine has the following storage declaration:

list: dc.w 1, 2, 3, 4

Further suppose that the number 4 is passed in as N and the address list is passed in as A to the subroutine strange. What is the answer returned by strange in (D0.W)?

(c)
Now suppose that the main program contains the following storage declaration:

list: dc.w 1, 2, 3, 4, 5

If the number 5 and the address list are passed into strange, then will strange return an answer in (D0.W)? If so, what is it? If not, why not?

(d)
If 1000 bytes of stack space is available for the stack frames of strange, then what is the largest value of N for which the subroutine strange will produce a correct answer.