I\'m looking to output an integer using pure assembly. I\'m using nasm on a 64-bit linux machine. At the moment I\'m looking for a way to output integers to debug a compiler
Here are some possible changes to the routine:
_printi:
pushf
push rax
push rbx
push rcx
push rdx
mov rax, [rsp+48]
mov rcx, 4
mov rbx, 10 ; --moved outside the loop
.start:
dec rcx
xor rdx, rdx
div rbx
add rdx, 48
mov [var+rcx], dl
cmp rax, 0
jne .start
; mov rax, [var] -- not used
; push rax -- not used
call _printc
; pop rax -- not used
pop rdx
pop rcx
pop rbx
pop rax
popf
ret
I also noted some limitations in the algorithm. If the number is larger than 9999, the code will continue to put digits outside of the allocated space, overwriting some other data. The routine is not fully reusable, i.e. if you print 123, then 9 it will come out as 129.