Problem 4. This problem is about two-dimensional arrays (See Section 3.8.3 in the text). The declaration int A[100] [200] declares an array of 100 rows of 200 columns each. An array reference A[i][j] refers to the element in the ith row, jth column. Now, memory is actually linear, so there is a question as to how to compute the address of element A[i][j] The C specification guarantees that such arrays are laid out in row-major order, which means that the elements of row 0 (i.e., all the columns of row 0) come first, followed by the elements of row 1, etc. (Remember: "[Row][Column]") (See Figure 3.16 in the text, also slides 20, 22 and 24 from the lecture "Implementing Data Structures" on Friday 15 September.) a. For the array A declared above (100 rows of 200 columns each), with starting address 200000, what is the address of element A[47] [101]? b. Assume a global array declared as int *ptrs [10] [20]. The address of ptrs is in %rbx. Assume the value of int variables r and c are in registers %rdi and %rsi, respectively, and the last statement of a function that returns a pointer to an int is return ptrs [r] [c]; Write assembly code to put the return value in %rax c. Suppose a two-dimensional array is declared: char foo[M] {N]; where M and N are constants defined elsewhere. If you know that foo[r] [c] (for some values of r and c) is the same as *(foo+120), is it possible to determine the exact values of M and N from that? If so, say what they are. If not say why not.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Problem 4. This problem is about two-dimensional arrays (See Section 3.8.3 in the text). The
declaration int A[100] [200] declares an array of 100 rows of 200 columns each. An array reference
A[i][j] refers to the element in the ith row, jth column. Now, memory is actually linear, so there
is a question as to how to compute the address of element A[i][j]
The C specification guarantees that such arrays are laid out in row-major order, which means
that the elements of row 0 (i.e., all the columns of row 0) come first, followed by the elements of row
1, etc. (Remember: "[Row][Column]") (See Figure 3.16 in the text, also slides 20, 22 and 24 from
the lecture "Implementing Data Structures" on Friday 15 September.)
a. For the array A declared above (100 rows of 200 columns each), with starting address 200000,
what is the address of element A[47] [101]?
b. Assume a global array declared as int *ptrs [10] [20]. The address of ptrs is in %rbx.
Assume the value of int variables r and c are in registers %rdi and %rsi, respectively, and
the last statement of a function that returns a pointer to an int is
return ptrs [r] [c];
Write assembly code to put the return value in %rax
c. Suppose a two-dimensional array is declared: char foo [M] {N]; where M and N are constants
defined elsewhere. If you know that foo[r] [c] (for some values of r and c) is the same as
*(foo+120), is it possible to determine the exact values of M and N from that? If so, say what
they are. If not say why not.
Transcribed Image Text:Problem 4. This problem is about two-dimensional arrays (See Section 3.8.3 in the text). The declaration int A[100] [200] declares an array of 100 rows of 200 columns each. An array reference A[i][j] refers to the element in the ith row, jth column. Now, memory is actually linear, so there is a question as to how to compute the address of element A[i][j] The C specification guarantees that such arrays are laid out in row-major order, which means that the elements of row 0 (i.e., all the columns of row 0) come first, followed by the elements of row 1, etc. (Remember: "[Row][Column]") (See Figure 3.16 in the text, also slides 20, 22 and 24 from the lecture "Implementing Data Structures" on Friday 15 September.) a. For the array A declared above (100 rows of 200 columns each), with starting address 200000, what is the address of element A[47] [101]? b. Assume a global array declared as int *ptrs [10] [20]. The address of ptrs is in %rbx. Assume the value of int variables r and c are in registers %rdi and %rsi, respectively, and the last statement of a function that returns a pointer to an int is return ptrs [r] [c]; Write assembly code to put the return value in %rax c. Suppose a two-dimensional array is declared: char foo [M] {N]; where M and N are constants defined elsewhere. If you know that foo[r] [c] (for some values of r and c) is the same as *(foo+120), is it possible to determine the exact values of M and N from that? If so, say what they are. If not say why not.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education