I wrote this code in asm x64 on an Intel processor on Linux and it should counts the number of digits of RDI content and returns the result into RAX. It simply divides RAX by 10 until RAX equals 0 (until quotient equals 0). At each loop, RCX increases :
bits 64
global _start
section .text
_start:
mov rdi,1234
push rcx
push rsi
push rdx
mov rsi,0xa
mov rax,rdi
xor rcx,rcx
func_loop:
cmp rax,0x0
jz func_fin
inc rcx
div rsi
jmp func_loop
func_fin:
mov rax,rcx
pop rdx
pop rsi
pop rcx
mov rax,0x3c ; sys_exit
mov rdi,0x0
syscall
When executed, the program seems to be in an infinite loop... GDB tells me this :
Could you tell me why RAX content is suddenly changing from 123 to 7378697629483820658 ? Did i misunderstand the use of DIV instruction ?
Thank you for all your attention to this.