Institutt for Informatikk
Universitetet i Bergen
I 125 - Innf°ring i Programoversettelse


Voluntary Exercise Set 11 (Gruppe°velser. 11)

  1. A repeat-until statement is a loop much like the while-statement, except that the test for exiting the loop is performed at the end of the loop rather than at the beginning. For example, the code for the body in the following loop would execute exactly once if x began with a value of -2, and would execute exactly three times if x began with a value of 5.

    repeat

    x = x - 2;

    until (x < 0)

    Suppose a repeat-until statement were added to the C- language.

    1. Describe an appropriate (intermediate or target) code arrangement for a repeat-until statement.
    2. Show a sequence of 3-address code instructions that is consistent with your answer to part a and implements the repeat-until statement shown above.
    3. Show a sequence of BVM-like intermediate code instructions that is consistent with your answer to part a and implements the repeat-until statement shown above.

  2. Consider the following C- program.

    int x;
    int y;

    int foo(int a[])
    {

    int ans;
    ans = (a[1]=3) + (x=y) + a[0];
    return ans;
    }

    int main(void)
    {

    int b[2];
    y=10;
    if (input()==1) output(foo(b));
    }

    1. Describe a map for the frames (activation records) that BVM would use to execute the C- program. That is, indicate exactly which locations in each frame correspond to each local variable, to each parameter and to the temporaries needed on the stack during the function's execution.
    2. Give a sequence of BVM-like intermediate code instructions that implement the C- program.
    3. Describe exactly what changes would need to be made to the BVM-like intermediate code in order to produce valid BVM target code.
    4. Give a sequence of 3-address intermediate code instructions that implement the C- program.