This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program areaString64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessStringsch:   .ascii "The string is at item : @ \n"
szCarriageReturn:  .asciz "\n"
szMessStringNfound: .asciz "The string is not found in this area.\n"
 
/* areas strings  */
szString1:  .asciz "Apples"
szString2:  .asciz "Oranges"
szString3:  .asciz "Pommes"
szString4:  .asciz "Raisins"
szString5:  .asciz "Abricots"
 
/* pointer items area 1*/
tablesPoi1:
pt1_1:        .quad szString1
pt1_2:        .quad szString2
pt1_3:        .quad szString3
pt1_4:        .quad szString4
ptVoid_1:     .quad 0
ptVoid_2:     .quad 0
ptVoid_3:     .quad 0
ptVoid_4:     .quad 0
ptVoid_5:     .quad 0
 
szStringSch:  .asciz "Raisins"
szStringSch1: .asciz "Ananas"
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss
sZoneConv:       .skip 30
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main:                      // entry of program
 
                           // add string 5 to area
    ldr x1,qAdrtablesPoi1  // begin pointer area 1
    mov x0,0               // counter
1:                         // search first void pointer
    ldr x2,[x1,x0,lsl 3]   // read string pointer address item x0 (4 bytes by pointer)
    cmp x2,0               // is null ?
    cinc x0,x0,ne          // no increment counter
    bne 1b                 // and loop
 
                           // store pointer string 5 in area  at position x0
    ldr x2,qAdrszString5   // address string 5
    str x2,[x1,x0,lsl 3]   // store address 
 
                           // display string at item 3
    mov x2,2               // pointers begin in position 0 
    ldr x1,qAdrtablesPoi1  // begin pointer area 1
    ldr x0,[x1,x2,lsl 3]
    bl affichageMess
    ldr x0,qAdrszCarriageReturn
    bl affichageMess
 
                           // search string in area 
    ldr x1,qAdrszStringSch
    //ldr x1,qAdrszStringSch1  // uncomment for other search : not found !!
    ldr x2,qAdrtablesPoi1  // begin pointer area 1
    mov x3,0
2:                         // search 
    ldr x0,[x2,x3,lsl 3]   // read string pointer address item x0 (4 bytes by pointer)
    cbz x0,3f              // is null ?  end search
    bl comparString
    cmp x0,0               // string = ?
    cinc x3,x3,ne          // no increment counter
    bne 2b                 // and loop
    mov x0,x3              // position item string
    ldr x1,qAdrsZoneConv   // conversion decimal
    bl conversion10S
    ldr x0,qAdrszMessStringsch
    ldr x1,qAdrsZoneConv 
    bl strInsertAtCharInc  // insert result at @ character
    bl affichageMess
    b 100f
3:                         // end search  string not found
    ldr x0,qAdrszMessStringNfound
    bl affichageMess
 
100:                       // standard end of the program
    mov x0,  0             // return code
    mov x8,EXIT            // request to exit program
    svc 0                  // perform the system call
qAdrtablesPoi1:         .quad tablesPoi1
qAdrszMessStringsch:    .quad szMessStringsch
qAdrszString5:          .quad szString5
qAdrszStringSch:        .quad szStringSch
qAdrszStringSch1:       .quad szStringSch1
qAdrsZoneConv:          .quad sZoneConv
qAdrszMessStringNfound: .quad szMessStringNfound
qAdrszCarriageReturn:   .quad  szCarriageReturn
/************************************/       
/* Strings comparaison              */
/************************************/      
/* x0 et x1 contains strings addresses */
/* x0 return 0 if equal */
/* return -1 if string x0 < string x1 */
/* return 1  if string x0 > string x1 */
comparString:
    stp x2,lr,[sp,-16]!         // save  registers
    stp x3,x4,[sp,-16]!         // save  registers
    mov x2,#0                   // indice
1:    
    ldrb w3,[x0,x2]             // one byte string 1
    ldrb w4,[x1,x2]             // one byte string 2
    cmp w3,w4
    blt 2f                      // less
    bgt 3f                      // greather
    cmp w3,#0                   // 0 final
    beq 4f                      // equal and end
    add x2,x2,#1                // 
    b 1b                        // else loop
2:
    mov x0,#-1                  // less
    b 100f
3:
    mov x0,#1                   // greather
    b 100f
4:
    mov x0,#0                   // equal
    b 100f
100:
    ldp x3,x4,[sp],16           // restaur  2 registers
    ldp x2,lr,[sp],16           // restaur  2 registers
    ret                         // return to address lr x30
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 