Question: Suppose we are generating code for an imperative language on a machine with 8-byte floating-point numbers, 4-byte integers, 1-byte characters, and 4-byte alignment for both

Suppose we are generating code for an imperative language on a machine with 8-byte floating-point numbers, 4-byte integers, 1-byte characters, and 4-byte alignment for both integers and floating-point numbers. Suppose further that we plan to use contiguous row-major layout for multidimensional arrays, that we do not wish to reorder fields of records or pack either records or arrays, and that we will assume without checking that all array subscripts are in bounds.
(a) Consider the following variable declarations:
A : array [1..10, 10..100] of real
i : integer
x : real
Show the code that our compiler should generate for the following assignment: x := A[3,i]. Explain how you arrived at your answer.

(b) Consider the following more complex declarations:
r : record
        x : integer
        y : char
        A : array [1..10, 10..20] of record
                z : real
                B : array [0..71] of char
j, k : integer

Assume that these declarations are local to the current subroutine. Note the lower bounds on indices in A; the first element is A[1,10].

Describe how r would be laid out in memory. Then show code to load r.A[2,j].B[k] into a register. Be sure to indicate which portions of the address calculation could be performed at compile time.

Step by Step Solution

3.31 Rating (172 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The address of A3i is A3L 1 S 1 iL 2 S 2 where A is the address of A L 1 1 L ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!