How to resolve the algorithm Address of a variable step by step in the AArch64 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Address of a variable step by step in the AArch64 Assembly programming language

Table of Contents

Problem Statement

Demonstrate how to get the address of a variable and how to set the address of a variable.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Address of a variable step by step in the AArch64 Assembly programming language

Source code in the aarch64 programming language

/* ARM assembly AArch64 Raspberry PI 3B */
/*  program adrvar.s   */
/*************************************/
/* Constantes                        */
/*************************************/
.equ STDOUT, 1
.equ WRITE,  64
.equ EXIT,   93
/*************************************/
/* Initialized data                  */
/*************************************/
.data
szMessage:      .asciz "Hello. \n"       // message
szRetourLigne:  .asciz "\n"
qValDeb:        .quad 5                   // value 5 in array of 8 bytes
/*************************************/
/* No Initialized data               */
/*************************************/
.bss
qValeur:  .skip  8                       // reserve 8 bytes in memory
/*************************************/
/* Program code                      */
/*************************************/
.text
.global main 
main:
    ldr x0,=szMessage                    // adresse of message short program
    bl affichageMess                     // call function
                                         //  or
    ldr x0,qAdrszMessage                 // adresse of message big program (size code > 4K)
    bl affichageMess                     // call function

    ldr x1,=qValDeb                      // adresse of variable -> x1  short program
    ldr x0,[x1]                          // value of iValdeb  -> x0
    ldr x1,qAdriValDeb                   // adresse of variable -> x1  big program
    ldr x0,[x1]                          // value of iValdeb  -> x0

    /* set variables  */
    ldr x1,=qValeur                      // adresse of variable -> x1  short program
    str x0,[x1]                          // value of x0 ->  iValeur
    ldr x1,qAdriValeur                   // adresse of variable -> x1  big program
    str x0,[x1]                          // value of x0 ->  iValeur
 
 
 /* end of  program */
    mov x0,0                             // return code
    mov x8,EXIT                          // request to exit program
    svc 0                                // perform the system call
qAdriValDeb:            .quad qValDeb
qAdriValeur:            .quad qValeur
qAdrszMessage:          .quad szMessage
qAdrszRetourLigne:      .quad szRetourLigne
/******************************************************************/
/*     String display with  size compute                          */ 
/******************************************************************/
/* x0 contains string address (string ended with zero binary) */
affichageMess:
    stp x0,x1,[sp,-16]!        // save  registers
    stp x2,x8,[sp,-16]!        // save  registers
    mov x2,0                   // size counter
1:                             // loop start
    ldrb w1,[x0,x2]            // load a byte
    cbz w1,2f                  // if zero -> end string
    add x2,x2,#1               // else increment counter
    b 1b                       // and loop
2:                             // x2 =  string size
    mov x1,x0                  // string address
    mov x0,STDOUT              // output Linux standard
    mov x8,WRITE               // code call system "write"
    svc 0                      // call systeme Linux
    ldp x2,x8,[sp],16          // restaur  2 registres
    ldp x0,x1,[sp],16          // restaur  2 registres
    ret                        // retour adresse lr x30

  

You may also check:How to resolve the algorithm Bézier curves/Intersections step by step in the ObjectIcon programming language
You may also check:How to resolve the algorithm Y combinator step by step in the F# programming language
You may also check:How to resolve the algorithm GSTrans string conversion step by step in the Wren programming language
You may also check:How to resolve the algorithm Empty string step by step in the COBOL programming language
You may also check:How to resolve the algorithm Introspection step by step in the BBC BASIC programming language