I share an algorithm that I have written myself. It is useful for incrementing any digit of a decimal number. That way, a conversion to decimal is not necessary.
Please excuse the mistakes. I am learning assembler and x86 architecture. I am sure that it is possible to improve and optimize it (thank you). This code obviously uses recursion. But it doesn't go through the unnecessary digits. Following the advice of Peter Cordes. I think the algorithm is very readable thanks to the labels. It is written using the NASM syntax. Tested on Intel i3 x86-64 CPU and Linux operating system.
section .data
number db "////////////////////////////////////////////////////////////////";For 64-digits integers
countN dd 0
section .bss
index resb 1
section .text
global CMAIN
INCREMENT:
;xor rax, rax
;mov eax, [index]
cmp byte[number+eax], "9"
jz EQUAL
jmp checkNEWdigit
EQUAL:
mov byte[number +eax],"0"
dec eax
jmp INCREMENT
NEWdigit:
mov byte[number + eax],"1"
inc byte[countN]
jmp FINISH
checkNEWdigit:
cmp byte[number + eax],"/" ;check if the position is empty
jz NEWdigit
inc byte[number+eax]
FINISH:
ret
CMAIN:
;Set the number to be increased- For example:
mov byte[number+59],"9"; Ten thousands
mov byte[number+60],"9"; Thousands
mov byte[number+61],"9"; Hundreds
mov byte[number+62],"9"; Tens
mov byte[number+63],"9"; Ones
;Until 64 digits
mov byte[countN],5 ;Set the number of digits that the number has at the beginning.
mov [index],byte 63 ;Set the position to be increased(63-ones;62-Tens;61-Hundreds..etc..),
xor rax, rax
mov eax, [index];the use of the variable "index" is for readability only.
call INCREMENT
;the next instructions are needed to calculate the position to be printed
mov rbx, 64 ;total of digits
sub rbx, [countN] ;sub number of digits used
add rbx,number;add the base
;print
xor rax,rax
mov rax, 1
mov rdi, 1
mov rsi, rbx
mov rdx, [countN]
syscall
;exit
mov rax,60
mov rdi, 2
syscall