Task

Demonstrate the different syntax and semantics provided for calling a function.



This may include:

   Calling a function that requires no arguments
   Calling a function with a fixed number of arguments
   Calling a function with optional arguments
   Calling a function with a variable number of arguments
   Calling a function with named arguments
   Using a function in statement context
   Using a function in first-class context within an expression
   Obtaining the return value of a function
   Distinguishing built-in functions and user-defined functions
   Distinguishing subroutines and functions
   Stating whether arguments are passed by value or by reference
   Is partial application possible and how


This task is not about defining functions.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program callfonct.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/***********************/
/* Initialized data */
/***********************/
.data
szMessage:      .asciz "Hello. \n"       // message
szRetourLigne:  .asciz "\n"
szMessResult:   .asciz "Resultat : "      // message result
 
/***********************/
/* No Initialized data */
/***********************/
.bss
sZoneConv:  .skip  100
 
.text
.global main 
main:
    ldr x0,=szMessage           // adresse of message  short program
    bl affichageMess            // call function with 1 parameter (x0)
 
                                // call function with parameters in register
    mov x0,#5
    mov x1,#10
    bl fonction1                // call function with 2 parameters (x0,x1)
    ldr x1,qAdrsZoneConv        // result in x0
    bl conversion10S            // call function with 2 parameter (x0,x1)
    ldr x0,=szMessResult
    bl affichageMess            // call function with 1 parameter (x0)
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
                                // call function with parameters on stack
    mov x0,#5
    mov x1,#10
    stp x0,x1,[sp,-16]!         // store  registers on stack
    bl fonction2                // call function with 2 parameters on the stack
                                // result in x0
    ldr x1,qAdrsZoneConv
    bl conversion10S            // call function with 2 parameter (x0,x1)
    ldr x0,=szMessResult
    bl affichageMess            // call function with 1 parameter (x0)
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
                                // end of  program
    mov x0, #0                  // return code
    mov x8, #EXIT               // request to exit program
    svc 0                       // perform the system call
qAdrsZoneConv:              .quad sZoneConv
qAdrszRetourLigne:          .quad szRetourLigne
/******************************************************************/
/*     call function parameter in register             */ 
/******************************************************************/
/* x0 value one */
/* x1 value two */
/* return in x0 */
fonction1:
    stp x2,lr,[sp,-16]!        // save  registers
    mov x2,#20
    mul x0,x0,x2
    add x0,x0,x1
    ldp x2,lr,[sp],16          // restaur  2 registres
    ret                        // retour adresse lr x30  
 
/******************************************************************/
/*     call function parameter in the stack             */ 
/******************************************************************/
/* return in x0 */
fonction2:
    stp fp,lr,[sp,-16]!        // save  registers
    add fp,sp,#16              // address parameters in the stack
    stp x1,x2,[sp,-16]!        // save  others registers
    ldr x0,[fp]                // second paraméter
    ldr x1,[fp,#8]             // first parameter
    mov x2,#-20
    mul x0,x0,x2
    add x0,x0,x1
    ldp x1,x2,[sp],16          // restaur  2 registres
    ldp fp,lr,[sp],16          // restaur  2 registres
    add sp,sp,#16              // very important, for stack aligned
    ret                        // retour adresse lr x30  
 
 
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
 