Task

Test whether an integer is even or odd.

There is more than one way to solve this task:

 Use the even and odd predicates, if the language provides them.
 Check the least significant digit. With binary integers, i bitwise-and 1 equals 0 iff i is even, or equals 1 iff i is odd.
 Divide i by 2. The remainder equals 0 iff i is even. The remainder equals +1 or -1 iff i is odd.
 Use modular congruences:
 i ≡ 0 (mod 2) iff i is even.
 i ≡ 1 (mod 2) iff i is odd.


 
/* ARM assembly AARCH64 Raspberry PI 3B and android arm 64 bits*/
/*  program oddEven64.s   */ 
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResultOdd:        .asciz " @ is odd (impair) \n"
sMessResultEven:       .asciz " @ is even (pair)  \n"
szCarriageReturn:      .asciz "\n"
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss
sZoneConv:        .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                                 //entry of program 
 
    mov x0,#5
    bl testOddEven
    mov x0,#12
    bl testOddEven
    mov x0,#2021
    bl testOddEven
100:                                  //standard end of the program 
    mov x0, #0                        //return code
    mov x8, #EXIT                     //request to exit program
    svc #0                            //perform the system call
 
qAdrszCarriageReturn:     .quad szCarriageReturn
qAdrsMessResultOdd:       .quad sMessResultOdd
qAdrsMessResultEven:      .quad sMessResultEven
qAdrsZoneConv:            .quad sZoneConv
/***************************************************/
/*     test if number is odd or even               */
/***************************************************/
// x0 contains à number
testOddEven:
    stp x1,lr,[sp,-16]!       // save  registres
    tst x0,#1                   //test bit 0 to one
    beq 1f                      //if result are all zéro, go to even
    ldr x1,qAdrsZoneConv        //else display odd message
    bl conversion10             //call decimal conversion
    ldr x0,qAdrsMessResultOdd
    ldr x1,qAdrsZoneConv        //insert value conversion in message
    bl strInsertAtCharInc
    bl affichageMess
    b 100f
1:
    ldr x1,qAdrsZoneConv
    bl conversion10             //call decimal conversion
    ldr x0,qAdrsMessResultEven
    ldr x1,qAdrsZoneConv        //insert conversion in message
    bl strInsertAtCharInc
    bl affichageMess
100:
    ldp x1,lr,[sp],16         // restaur des  2 registres
    ret
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 