I ask the user to give me a number. I receive that number as a string and I want to iterate through each char of the string to check its content. I have written this code where numero_a_convertir is the pointer to the string the user gave me:
;* BASE 8 A BINARIO
convertir_octal_a_base2:
mov rbx, 0
cmp dword[numero_a_convertir + rbx], "0"
je imprimir
cmp dword[numero_a_convertir + rbx], "1"
je imprimir
cmp dword[numero_a_convertir + rbx], "2"
je imprimir
cmp dword[numero_a_convertir + rbx], "3"
je imprimir
cmp dword[numero_a_convertir + rbx], "4"
je imprimir
cmp dword[numero_a_convertir + rbx], "5"
je imprimir
cmp dword[numero_a_convertir + rbx], "6"
je imprimir
cmp dword[numero_a_convertir + rbx], "7"
je imprimir
jmp fin_conversion
imprimir:
mov rcx, MENSAJE_A_IMPRIMIR_CHAR
mov rdx, [numero_a_convertir + rbx]
sub rsp, 32
call printf
add rsp, 32
fin_conversion:
ret
If the user inputs a string with only 1 character, for example "1", it works, because RBX is set on 0. But if the user inputs more than 1 character, for example "12" or "12345", it doesn't work anymore.
The same thing if I set RBX on 2. If the input is "123", it works. If the input is "12345", it breaks.
Why am I not being able to access char number 3 of a 5-char string?