Optional material: advanced address mode for accessing array elements

  • Offset used to access the array element A[i]:

      offset = 1*i    if A is a  byte typed array
    
      offset = 2*i    if A is a short typed array
    
      offset = 4*i    if A is an  int typed array
    

  • Recall that:

         x  <<  12 * x 
         x  <<  24 * x 
    

    Examples:

              x                  x << 1               x << 2 
         ----------------------------------------------------------
          00000011 (= 3)     00000110 (= 2*3)    00001100 (= 4*3)
    

Optional material: advanced address mode for accessing array elements

  • ARM's advanced addressing mode used to access array elements:

       ldrXX  rN, [rN, rk, LSL #n] // Advanced load instruction for arrays
    
       strXX  rN, [rN, rk, LSL #n] // Advanced load instruction for arrays
    

  • The memory address used by ldrXX rN, [rN, rk, LSL #n]

            memory address = rN + ( rk << n )
    
     i.e.:  memory address = rN +   2n*rk  
    

    Examples:

      ldrsb  rN, [rN, rk, LSL #0]   // Load byte data at array index rk
    
      ldrsh  rN, [rN, rk, LSL #1]   // Load short data at array index rk
    
      ldr    rN, [rN, rk, LSL #2]   // Load int data at array index rk
    

Postscript

  • This advanced addressing mode is not available in EGTAPI

    • EGTAPI is based on an earlier release of ARM

    • This advanced "scale" register index mode is not available

  • Result:

    • You will get compiler error if you try to use it...

DEMO: demo/asm/3-array/array-ldr-advanced.s