Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program rechMax64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
szMessResult:  .ascii "Max number is =  @ rank = @ address (hexa) = @ \n"      // message result
 
tTableNumbers:    .quad 50
                  .quad 12
                  .quad -1000
                  .quad 40
                  .quad 255
                  .quad 60
                  .quad 254
.equ NBRANKTABLE,   (. - tTableNumbers) / 8  // number table posts
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss 
sZoneConv:         .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                        // entry of program 
    ldr x1,qAdrtTableNumbers
    mov x2,0
    ldr x4,[x1,x2,lsl #3]    // load first number
    mov x3,x2                // save first indice
    add x2,x2,1              // increment indice
1:
    cmp x2,#NBRANKTABLE      // indice ? maxi
    bge 2f                   // yes -> end search
    ldr x0,[x1,x2,lsl #3]    // load other number
    cmp x0,x4                // > old number max
    csel x4,x0,x4,gt         // if > x4 = x0 else x4=x4
    csel x3,x2,x3,gt         // if > x3 = x2 else x3=x3
    add x2,x2,1              // increment indice
    b 1b                     // and loop
 
2:
    mov x0,x4
    ldr x1,qAdrsZoneConv
    bl conversion10S         // decimal conversion
    ldr x0,qAdrszMessResult
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc    // insert result at first @ character
    mov x5,x0                // save address message
    mov x0,x3
    ldr x1,qAdrsZoneConv     // conversion rank maxi
    bl conversion10S         // decimal conversion
    mov x0,x5                // message address
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc    // insert result at Second @ character
    mov x5,x0                // save message address
    ldr x0,qAdrtTableNumbers
    lsl x3,x3,3
    add x0,x0,x3
    ldr x1,qAdrsZoneConv     // conversion address maxi
    bl conversion16          // hexa conversion
    mov x0,x5
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc    // insert result at third @ character
    bl affichageMess         // display message final
 
 
100:                         // standard end of the program 
    mov x0,0                 // return code
    mov x8,EXIT              // request to exit program
    svc 0                    // perform the system call
qAdrtTableNumbers:    .quad  tTableNumbers
qAdrszMessResult:     .quad szMessResult
qAdrsZoneConv:        .quad sZoneConv
 
/******************************************************************/
/*     conversion  hexadecimal register                           */ 
/******************************************************************/
/* x0 contains value and x1 address zone receptrice   */
conversion16:
    stp x0,lr,[sp,-48]!        // save  registres
    stp x1,x2,[sp,32]          // save  registres
    stp x3,x4,[sp,16]          // save  registres
    mov x2,#60                 // start bit position
    mov x4,#0xF000000000000000 // mask
    mov x3,x0                  // save entry value
1:                             // start loop
    and x0,x3,x4               // value register and mask
    lsr x0,x0,x2               // right shift
    cmp x0,#10                 // >= 10 ?
    bge 2f                     // yes
    add x0,x0,#48              // no is digit
    b 3f
2:
    add x0,x0,#55              // else is a letter A-F
3:
    strb w0,[x1],#1            // load result  and + 1 in address
    lsr x4,x4,#4               // shift mask 4 bits left
    subs x2,x2,#4              // decrement counter 4 bits <= zero  ?
    bge 1b                     // no -> loop
 
100:                           // fin standard de la fonction
    ldp x3,x4,[sp,16]          // restaur des  2 registres
    ldp x1,x2,[sp,32]          // restaur des  2 registres
    ldp x0,lr,[sp],48          // restaur des  2 registres
    ret    
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 