Assume we have a language that allows arrays and that parameters in this language can be passed by value, by reference, by value-result, or by name. Consider the following program:
integer A[4]. integer k. void f{ integer x, integer y } [ x = x + 1. k = k + 1. A[k] = A[k] * 2. y = y + 1. write << x. write << y. write << k. write << A[k]. ] void main{} [ k = 0. while k < 4 [ A[k] = k. k = k + 1. ] k = 0. f(k, A[k]). write << k. write << A[0]. write << A[1]. write << A[2]. write << A[3]. ]
Below is a link to a file that contain six pictures. The first four pictures contain outlines of f's activation record, as well as the space in the static data area for globals k and A. The last two pictures contain space for recording the output of the program.
For the first four pictures, you should fill in the values for all of the variables as they would be just before function f returns. For each picture, assume the parameter-passing modes for f's parameters indicated in that picture.
For the last two pictures, you should fill in the values that would be printed by functions f and main, assuming that f's parameters are both passed by value-result or both passed by name (as indicated in the pictures).
Last Updated: 4/3/2024 © 2024 CS 536