This code is supposed to print an integer in intel x86 assembly; however, when I run it, it produces no output and I don't know why. Also, I want someone to explain how can I retrieve an element from the stack properly as I don't quite understand the logic under the (next) label in the code
section .data
msg db "Hello", 0xa
len equ $ - msg
section .text
global _start
_start:
mov rax, 947852 ; the number that we are going to print
xor r10, r10 ; basically, makes rsi equal to 0
loop:
xor rdx, rdx ; zeroes the rdx to place the remainder in it
mov rbx, 10 ; what we are going to divide by
div rbx ; div rax by rbx and places the remainder in rdx
add rdx, 48 ; convert it to its ascii equiavlent
push rdx ; push this ascii on the stack
inc r10 ; a counter of the digits in the number we want to print
cmp rax, 0 ;
jz next ; if the number is now zero, then go to the fucntion that would print it in reverse
jmp loop
next:
cmp r10, 0
jz exit
dec r10
mov rax, 4 ; syscall for sys_Write
mov rcx, rsp ;what we want to print
mov rbx, 1 ; stdout as the destination
mov rdx, 1 ; its size
int 0x80 ; interrupt the processor to perform the system call
add rsp, 1
jmp next ; loop again
exit:
mov rax, 1 ; syscall for exiting properly
mov rbx, 0 ; error code 0
int 0x80 ; interrupt to exit