
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

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




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