this is the code that runs properly in NASM-v2.13.02 properly...
section .data
digit db 0,10;defines the first number with newline character
section .text
global _start
_start:
mov rbx, 48 ;ascii 48 => '0'
mov rcx, 57 ;ascii 57 => '9'
loop: call _printRBX ;print rbx
add rbx, 1 ;rbx += 1
cmp rbx, 57 ;rbx <= 57 ? (true/false)
jle loop ; jump to "loop" if above is true
mov rax, 60 ;id=sysexit
mov rdi, 0 ;errorcode=0
syscall
_printRBX: ;prints last byte of rbx
mov [digit],bl ;move pointer of digits to last 1byte of rbx
mov rax, 1 ;id=syswrite
mov rdi, 1 ;desc=standard output
mov rsi, digit ;buffer input
mov rdx, 2 ;write byte size
syscall
ret
While the moment "57" in label "loop" is replaced with rcx...it becomes an infinite loop!!
section .data
digit db 0,10;defines the first number with newline character
section .text
global _start
_start:
mov rbx, 48 ;ascii 48 => '0'
mov rcx, 57 ;ascii 57 => '9'
loop: call _printRBX ;print rbx
add rbx, 1 ;rbx += 1
cmp rbx, rcx ;rbx <= rcx ? (true/false)
jle loop ; jump to "loop" if above is true
mov rax, 60 ;id=sysexit
mov rdi, 0 ;errorcode=0
syscall
_printRBX: ;prints last byte of rbx
mov [digit],bl ;move pointer of digits to last 1byte of rbx
mov rax, 1 ;id=syswrite
mov rdi, 1 ;desc=standard output
mov rsi, digit ;buffer input
mov rdx, 2 ;write byte size
syscall
ret
Please let me understand how this happens and how can I resolve this!! Thanks!