Number to ascii in armv8 assembly

65 views Asked by At

I need help converting numbers to ASCII. This is my code so far:

.global itoascii

itoascii:

    /* Initialize variables */
    mov x1, #10               /* Divisor */
    mov x2, buffer            /* Buffer address */

convert_loop:
    udiv x3, x0, x1           /* Divide the number by 10, quotient in x3, remainder in x0 */
    add x4, x0, #'0'          /* Convert remainder to ASCII */
    strb w4, [x2], #1         /* Store ASCII character in buffer and increment buffer pointer */

    cmp x3, #0                /* Check if quotient is zero */
    beq end_conversion        /* If quotient is zero, exit the loop */

    mov x0, x3                /* Update the number with the quotient */
    b convert_loop            /* Repeat the process */

end_conversion:
    mov x0, x2                /* Return the address of the buffer */
    ret

.data
    /* Put the converted string into buffer,
       and return the address of buffer */
    buffer: .fill 128, 1, 0
0

There are 0 answers