Homework 5
CS536-S24 Intro to PLs and Compilers


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.

Link to pdf file


Last Updated: 4/3/2024     © 2024 CS 536