Task

Create and display the sequence of binary digits for a given   non-negative integer.

   The decimal value      5   should produce an output of               101
   The decimal value     50   should produce an output of            110010
   The decimal value   9000   should produce an output of    10001100101000

The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used.

The output produced should consist just of the binary digits of each number followed by a   newline.

There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program binarydigit.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
 
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
sMessAffBindeb:  .asciz "The decimal value  "
sMessAffBin:     .asciz " should produce an output of "
szRetourLigne:   .asciz "\n"
 
/*******************************************/
/* Uninitialized data                       */
/*******************************************/
.bss
sZoneConv:                   .skip 100
sZoneBin:                    .skip 100
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main:                /* entry of program  */
    mov x5,5
    mov x0,x5
    ldr x1,qAdrsZoneConv
    bl conversion10S
    mov x0,x5
    ldr x1,qAdrsZoneBin
    bl conversion2      // binary conversion and display résult
    ldr x0,qAdrsZoneBin
    ldr x0,qAdrsMessAffBindeb
    bl affichageMess
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrsMessAffBin
    bl affichageMess
    ldr x0,qAdrsZoneBin
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
    /* other number */
    mov x5,50
    mov x0,x5
    ldr x1,qAdrsZoneConv
    bl conversion10S
    mov x0,x5
    ldr x1,qAdrsZoneBin
    bl conversion2      // binary conversion and display résult
    ldr x0,qAdrsZoneBin
    ldr x0,qAdrsMessAffBindeb
    bl affichageMess
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrsMessAffBin
    bl affichageMess
    ldr x0,qAdrsZoneBin
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
    /* other number */
    mov x5,-1
    mov x0,x5
    ldr x1,qAdrsZoneConv
    bl conversion10S
    mov x0,x5
    ldr x1,qAdrsZoneBin
    bl conversion2      // binary conversion and display résult
    ldr x0,qAdrsZoneBin
    ldr x0,qAdrsMessAffBindeb
    bl affichageMess
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrsMessAffBin
    bl affichageMess
    ldr x0,qAdrsZoneBin
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
    /* other number */
    mov x5,1
    mov x0,x5
    ldr x1,qAdrsZoneConv
    bl conversion10S
    mov x0,x5
    ldr x1,qAdrsZoneBin
    bl conversion2      // binary conversion and display résult
    ldr x0,qAdrsZoneBin
    ldr x0,qAdrsMessAffBindeb
    bl affichageMess
    ldr x0,qAdrsZoneConv
    bl affichageMess
    ldr x0,qAdrsMessAffBin
    bl affichageMess
    ldr x0,qAdrsZoneBin
    bl affichageMess
    ldr x0,qAdrszRetourLigne
    bl affichageMess
 
 
100:                            // standard end of the program */
    mov x0, #0                  // return code
    mov x8, #EXIT               // request to exit program
    svc 0                       // perform the system call
qAdrsZoneConv:         .quad sZoneConv
qAdrsZoneBin:           .quad sZoneBin     
qAdrsMessAffBin:       .quad sMessAffBin
qAdrsMessAffBindeb:    .quad sMessAffBindeb
qAdrszRetourLigne:     .quad szRetourLigne
/******************************************************************/
/*     register conversion in binary                              */ 
/******************************************************************/
/* x0 contains the register */
/* x1 contains the address of receipt area */
conversion2:
    stp x2,lr,[sp,-16]!        // save  registers
    stp x3,x4,[sp,-16]!        // save  registers
    clz x2,x0                  // number of left zeros bits 
    mov x3,64
    sub x2,x3,x2               // number of significant bits
    strb wzr,[x1,x2]           // store 0 final 
    sub x3,x2,1                // position counter of the written character
2:                             // loop
    tst x0,1                   // test first bit 
    lsr x0,x0,#1               // shift right one bit
    bne 3f
    mov x4,#48                 // bit = 0 => character '0'
    b 4f
3:
    mov x4,#49                 //   bit = 1   => character '1' 
4:
    strb w4,[x1,x3]            // character in reception area at position counter
    sub x3,x3,#1
    subs x2,x2,#1              //  0 bits ?
    bgt 2b                     // no!  loop
 
100:
    ldp x3,x4,[sp],16          // restaur  2 registres
    ldp x2,lr,[sp],16          // restaur  2 registres
    ret                        // retour adresse lr x30  
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
 