Task

Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number.

Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached.



Related task

   Integer sequence   is a similar task without the use of octal numbers.


 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program countOctal64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResult:        .ascii "Count : "
sMessValeur:        .fill 11, 1, ' '            // size => 11
szCarriageReturn:   .asciz "\n"
 
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                                             // entry of program 
    mov x20,0                                     // loop indice
1:                                                // begin loop
    mov x0,x20
    ldr x1,qAdrsMessValeur
    bl conversion8                                // call conversion octal
    ldr x0,qAdrsMessResult
    bl affichageMess                              // display message
    add x20,x20,1
    cmp x20,64
    ble 1b
 
 
100:                                              // standard end of the program 
    mov x0,0                                      // return code
    mov x8,EXIT                                   // request to exit program
    svc 0                                         // perform the system call
 
qAdrsMessValeur:          .quad sMessValeur
qAdrszCarriageReturn:     .quad szCarriageReturn
qAdrsMessResult:          .quad sMessResult
 
 
/******************************************************************/
/*     Converting a register to octal                             */ 
/******************************************************************/
/* x0 contains value and x1 address area   */
/* x0 return size of result (no zero final in area) */
/* area size => 11 bytes          */
.equ LGZONECAL,   10
conversion8:
    stp x1,lr,[sp,-16]!            // save  registers
    mov x3,x1
    mov x2,LGZONECAL
 
1:                                 // start loop
    mov x1,x0
    lsr x0,x0,3                    // / by 8
    lsl x4,x0,3
    sub x1,x1,x4                   // compute remainder x1 - (x0 * 8)
    add x1,x1,48                   // digit
    strb w1,[x3,x2]                // store digit on area
    cmp x0,0                       // stop if quotient = 0 
    sub x4,x2,1
    csel x2,x4,x2,ne
    bne 1b                         // and loop
                                   // and move digit from left of area
    mov x4,0
2:
    ldrb w1,[x3,x2]
    strb w1,[x3,x4]
    add x2,x2,1
    add x4,x4,1
    cmp x2,LGZONECAL
    ble 2b
                                   // and move spaces in end on area
    mov x0,x4                      // result length 
    mov x1,' '                     // space
3:
    strb w1,[x3,x4]                // store space in area
    add x4,x4,1                       // next position
    cmp x4,LGZONECAL
    ble 3b                         // loop if x4 <= area size
 
100:
 
    ldp x1,lr,[sp],16              // restaur  2 registers
    ret                            // return to address lr x30
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 