Defining an uninitialized array in High Level Language
 

  • Array in a high level programming language are defined as follows:

           int   a[10];   
        
        or short b[15];
      
        or byte  c[20];
      

  • The effect of an array definition is:

      • reserve memory space of the array

  • The number of (consecutive) memory cells reserved is equal to:

         array-size × array-elem-type-size    
      

Define an uninitialized array in assembler programming - byte typed array

  • A char (= byte) array in a high level programming language (like C):

         char a[10];      
      

    is translated into ARM assembler as follows:

         a:  .skip 10   // 10 × 1 = 10 bytes   
      

  • The label a will be equal to the memory address of the first array element
 

DEMO file: /home/cs255001/demo/asm/3-array/array-def.s

Define an uninitialized array in assembler programming - short typed array

  • A short array in a high level programming language (like C):

         short b[15];      
      

    is translated into ARM assembler as follows:

         b:  .skip 30   // 15 × 2 = 30 bytes   
      

  • The label b will be equal to the memory address of the first array element
 

DEMO file: /home/cs255001/demo/asm/3-array/array-def.s

Define an uninitialized array in assembler programming - int typed array

  • A int array in a high level programming language (like C):

         int c[20];      
      

    is translated into ARM assembler as follows:

         c:  .skip 80   // 20 × 4 = 80 bytes   
      

  • The label c will be equal to the memory address of the first array element
 

DEMO file: /home/cs255001/demo/asm/3-array/array-def.s

Insightful question:   how do we tell the data type of an array ?

  • What is the translation of the following array variables definitions:

         (1) byte  A[100];    ???
      
         (2) short A[50];     ???
      
         (3) int   A[25];     ???             
      

  • Answer:   all the array definitions will translate to:

         A:  .skip 100                     
      


  • Question:

    • How can you tell what is the data type of the array A in assembler ???

    Hint:   why will the compiler report an error when the data type is not known ?

Insightful question:   how do we tell the data type of an array ?

You can tell the data type of array from how the array elements are used:

  • When you access a byte typed array, you must use:

         ldrsb   ...
         strb    ...        
      

  • When you access a short typed array, you must use:

         ldrsh   ...
         strh    ...        
      

  • When you access a int typed array, you must use:

         ldr   ...
         str   ...        
      


  • Without info of the data type, a compiler cannot select which load instruction to use!!

Defining an initialized byte array
 

High level programming construct:

  char A[ ] = {11, 12, 13, 14, 15}; // initialized array  
   
 

is translated to the following assembler construct:

  A:  .byte 11, 12, 13, 14, 15  // initialized array
   

The .byte 11, 12, 13, 14, 15 directive will put the 8 bits 2s complement codes for 11, 12, 13, 14, 15 into 5 consecutive memory cells

Defining an initialized short array
 

High level programming construct:

 short B[ ] = {111, 112, 113, 114, 115}; // init array
   
 

is translated to the following assembler construct:

  B: .2byte 111, 112, 113, 114, 115  // init array  
   

The .2byte 111, 112, 113, 114, 115 directive will put the 16 bits 2s complement codes for 111, 112, 113, 114, 115 into 10 consecutive memory cells

Defining an initialized int array
 

High level programming construct:

   int C[ ] = {1111, 1112, 1113, 1114, 1115};
   
 

is translated to the following assembler construct:

  C: .4byte 1111, 1112, 1113, 1114, 1115    
   

The .4byte 1111, 1112, 1113, 1114, 115 directive will put the 32 bits 2s complement codes for 1111, 1112, 1113, 1114, 1115 into 20 consecutive memory cells