I'm using NASM on my 64 bit linux machine, I'm trying to simply:
- take an array of characters (digits)
- convert them to integers
- print them as integers
The issue is after I call
movzx rsi, [array+rcx], the value of rcx has changed (I learned this through debugging with gdb). Why is this?
My code:
array db "012345678"
fmt db "%d", 10, 0
...
...
; convert chars to integers
mov rcx, 9
L1:
dec rcx
sub [array+rcx], byte "0"
jnz L1
; print as integers
mov rcx, 0
L2:
mov rdi, fmt
movzx rsi, byte [array+rcx] ; rcx changes after this
xor rax, rax
call printf
inc rcx
cmp rcx, 8
jle L2
ret
But it keeps spitting out 2s endlessly.
if I preserve rcx in the stack, or use a different register for counting, it works. Is movzx suppose to destroy rcx?
also bonus question, feel free to disreguard, am I iterating through the array correctly?