Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Storage-mapping functions. (10 points) Suppose we are generating code for an imperative PL on a machine with 8-byte floating- point numbers, 4-byte integers, and

image text in transcribed

2. Storage-mapping functions. (10 points) Suppose we are generating code for an imperative PL on a machine with 8-byte floating- point numbers, 4-byte integers, and 1-byte characters. Also assume that characters, integers and floating-point numbers must each align to the left of a word (32-bits, or 4- bytes, long). We plan to use a contiguous row-major layout for multidimensional arrays. Furthermore, we do not wish to reorder fields of records or to pack either records or arrays. And 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; Show the storage mapping function Loc for this array A and then use it to compute the address of element A[3,1]. Assume Loc( A[ 1, 10])= 1234. (b) Now consider the following more complex declarations: R: record X: integer; Y: char; A: array [1:10, 10:20 ] of record Z: real; B: array [ 10:71] of char; end record; end record; I, K: integer; Assume that these declarations are local to the current subprogram. Note the lower bounds on indices in A; the first element is A[ 1, 10] which is stored in location 2000. Compute the address of the record component R.A[ 2 , J].B[K]. 2. Storage-mapping functions. (10 points) Suppose we are generating code for an imperative PL on a machine with 8-byte floating- point numbers, 4-byte integers, and 1-byte characters. Also assume that characters, integers and floating-point numbers must each align to the left of a word (32-bits, or 4- bytes, long). We plan to use a contiguous row-major layout for multidimensional arrays. Furthermore, we do not wish to reorder fields of records or to pack either records or arrays. And 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; Show the storage mapping function Loc for this array A and then use it to compute the address of element A[3,1]. Assume Loc( A[ 1, 10])= 1234. (b) Now consider the following more complex declarations: R: record X: integer; Y: char; A: array [1:10, 10:20 ] of record Z: real; B: array [ 10:71] of char; end record; end record; I, K: integer; Assume that these declarations are local to the current subprogram. Note the lower bounds on indices in A; the first element is A[ 1, 10] which is stored in location 2000. Compute the address of the record component R.A[ 2 , J].B[K]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago