How to resolve the algorithm Call a function step by step in the AArch64 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Call a function step by step in the AArch64 Assembly programming language

Table of Contents

Problem Statement

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

This may include:

This task is not about defining functions.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Call a function step by step in the AArch64 Assembly programming language

Source code in the aarch64 programming language

/* 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"

  

You may also check:How to resolve the algorithm Discordian date step by step in the Java programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Falcon programming language
You may also check:How to resolve the algorithm Forest fire step by step in the C# programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the 68000 Assembly programming language
You may also check:How to resolve the algorithm The sieve of Sundaram step by step in the Java programming language