Questions on arrays

  1. Give a declaration for an array of


  2. A. Give a declaration of an array of 26 characters (called letters), where each element is initialized to a lower case letter of the alphabet. letters[0] is 'a', letters[1] is 'b', and so on to letters[25] is 'z'.

    B. Give code to initialize each element of an array of 26 characters declared with
         letters:  .byte  '\0':26
      
    to do the same thing as the first part of this question.

    C. Identify each of parts A and B as either a static initialization or a dynamic initialization of the array.
  3. Does MIPS assembly language (MAL) provide a way to declare an array without specifying an initial value for each element?
  4. Write a MAL program that dynamically stores n! in elements of an array of integers. The index of each array element is n. Do this for an array of 10 integers.


  5. A. Give a declaration for a 2-dimensional array of integers, with 6 rows and 10 columns, where each integer array element is initialized to the value 0.

    B. What important piece of information has been omitted from this question specification?

    C. Does this important piece of information matter? Why or why not?
  6. A 4 row by 7 column array of integers has been declared with
    int_array:  .word  0:28    # 4 x 7 array of integers
    
    This array is stored in row major order. Write a MAL code fragment that initializes each element of the array to be the sum of its row index and column index. A partial diagram of the array (after this code executes) might appear as:
       0  1  2  3  4  5  6   (column indices)
    
       0  1  2  3  4  5  6   (row with index 0)
       1  2  3  4  5  6  7   (row with index 1)
       2  3  4  5  6  7      (partial row with index 2)
                             (missing row with index 3)
    
Copyright © Karen Miller, 2007