Reading a byte typed array element with a constant index - example: A[5]
 

Definition of array variable:

   byte A[10];   

Problem:

  • Fetch the value in A[5] into the register r0

Reading a byte typed array element with a constant index - example: A[5]
 

Address of array element A[5]:

 

Reading a byte typed array element with a constant index - example: A[5]
 

ARM instructions to fetch A[5] into register r0:

    .text

                               
   // Given that A is a byte typed array
  
   // Write ARM instructions to fetch A[5] into register R0

   // Note: we can pre-compute the offset using the index 5 !



   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  // array
   

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

Reading a byte typed array element with a constant index - example: A[5]
 

ARM instructions to fetch A[5] into register r0:

    .text

   
   

  
    // The load instruction needed is:
       
    ldrsb   r0, [r1, #n]     // Loads A[5] into r0
                             // What offset n must we use ?

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  // array
   

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

Reading a byte typed array element with a constant index - example: A[5]
 

ARM instructions to fetch A[5] into register r0:

    .text

   

  
    // Preparation:
    //    r1 = base address of array A

    ldrsb   r0, [r1, #5]     // Loads A[5] into r0
         

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  // array
   

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

Reading a byte typed array element with a constant index - example: A[5]
 

ARM instructions to fetch A[5] into register r0:

    .text

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A  

    /* ----------------------------------------
       Address of A[5] = base addr + 5*1 bytes
       ---------------------------------------- */
    ldrsb   r0, [r1, #5]     // Load A[5] into r0


   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  // array
   

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

Updating a byte typed array element with a constant index - example: A[5] = 99
 

Definition of array variable:

   byte A[10];   

Problem:

  • Update the value in A[5] to 99 (A[5] = 99)

Updating a byte typed array element with a constant index - example: A[5] = 99
 

Address of array element A[5]:

 

Updating a byte typed array element with a constant index - example: A[5] = 99
 

ARM instructions to update A[5] = 99:

    .text

  
   

    // Given that A is a byte typed array

   
    // Translate:  A[5] = 99;  into ARM assembler code
      
    // Note: we can pre-compute the offset using the index 5 !


   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   

Updating a byte typed array element with a constant index - example: A[5] = 99
 

ARM instructions to update A[5] = 99:

    .text

  
  

  

 
    // The store instruction that you can use:
       
    strb   r0, [r1, #n]     // Write r0 (= 99) into A[5] 
                            // What offset msut we use ?

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   

Updating a byte typed array element with a constant index - example: A[5] = 99
 

ARM instructions to update A[5] = 99:

    .text

  
  

  
    // Preparations needed:
    //    r0 = 99
    //    r1 = base address of array A
       
    strb   r0, [r1, #5]     // Write r0 (= 99) into A[5] 
                     

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   

Updating a byte typed array element with a constant index - example: A[5] = 99
 

ARM instructions to update A[5] = 99:

    .text

    mov     r0, #99           // r0 = 99

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A

    /* ----------------------------------------
       Address of A[5] = base addr + 5*1 bytes
       ---------------------------------------- */
    strb   r0, [r1, #5]     // Write r0 (= 99) into A[5] 


   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   

Reading a byte typed array element with a variable index - example: A[i]
 

Definition of array and index variables:

   byte A[10]; 
   int  i;  

Problem:

  • Fetch the value in A[i] into the register r0

Reading a byte typed array element with a variable index - example: A[i]
 

Address of array element A[i]:

 

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text


    // Given:
    //    int i;
    //    a byte array A

    // Problem: fetch A[i] into register r0

    // Note: the offset depends on the value in i
    //       The offset can not be pre-calculated !!!
     
    

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text

    
   

    // Preparations ?
  
   
   
    // The load instruction that must be use
    // to fetch the value in A[i]:

    ldrsb   r0, [r1, r2]     // Load A[i] into r0

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text

    
   

    // Preparations:
    //    r1 = base address of array A
    //    r2 = offset computed using index i
   
 
   

    ldrsb   r0, [r1, r2]     // Load A[i] into r0

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A

    // Preparation:
    //    r2 = offset computed using index i


    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */
    ldrsb   r0, [r1, r2]     // Load A[i] into r0

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A

    // Preparation:
    //    r2 = i


    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */
    ldrsb   r0, [r1, r2]     // Load A[i] into r0

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Reading a byte typed array element with a variable index - example: A[i]

ARM instructions to fetch A[i] into register r0:

    .text

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A

    movw    r2, #:lower16:i
    movt    r2, #:upper16:i   // r2 = address of i
    ldr     r2, [r2]          // r2 = i  (offset)

    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */
    ldrsb   r0, [r1, r2]     // Load A[i] into r0

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4
   

Updating a byte typed array element with a variable index - example: A[i] = 99
 

Definition of array and index variables:

   byte A[10];  
   int  i; 

Problem:

  • Update the value in A[i] to 99 (A[i] = 99)

Updating a byte typed array element with a variable index - example: A[i] = 99
 

Address of array element A[i]:

 

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text


 
    // Given:
    //    int i;
    //    a byte array A

    // Problem: translate A[i] = 99 into ARM assembler code

    // Note: the offset depends on the value in i
    //       The offset can not be pre-calculated !!!




   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4 

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text


    



    // Preparations ?
    
    

    // The store instruction that must be use
    // to write the value to A[i]:
     
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4  

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text






    // Preparations ?
    //    r0 = 99
    //    r1 = base address of array A
    //    r2 = offset computed using index i
    

     
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4  

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text

    movw    r0, #99           // r0 = 99





    // Preparations ?
    //    r1 = base address of array A
    //    r2 = offset computed using index i
    

     
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4  

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text

    movw    r0, #99           // r0 = 99

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A


    // Preparations ?
    //    r2 = offset computed using index i
    
    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */   
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4  

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text

    movw    r0, #99           // r0 = 99

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A


    // Preparations ?
    //    r2 = i (offset)
    
    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */   
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4  

Updating a byte typed array element with a variable index - example: A[i] = 99

ARM instructions to update A[i] = 99:

    .text

    movw    r0, #99           // r0 = 99

    movw    r1, #:lower16:A
    movt    r1, #:upper16:A   // r1 = base address of array A

    movw    r2, #:lower16:i
    movt    r2, #:upper16:i   // r2 = address of i
    ldr     r2, [r2]          // r2 = i (offset)

    /* ----------------------------------------
       Address of A[i] = base addr + i*1 bytes
       ---------------------------------------- */
    strb   r0, [r1, r2]     // Write r0 (= 99) into A[i] 

   .data
A: .byte   1, 2, 3, 4, 5, 6, 7, 8, 9, 10  //  array
   .align  2
i: .4byte  4