linux - Printing a number in x86-64 assembly -


okay, trying print number (up 18446744073709551616) in x86-64 assembly linux. can please tell me why program not work? happens runs , exits. thank can give!

global _start section .text  ;printchar ; mov [letter],rax ;  ; mov rax,1 ; mov rdi,1 ; mov rsi,letter ; mov rdx,1 ; syscall ; ret  printdec:  mov r9,18          ;so can point end of buffer  mov r10,0  start:  mov r8,number  mov rdx,0          ;clear out rdx avoid errors  mov rbx,10         ;what divide   div rbx            ;divide our number ten   cmp rax,0          ;if our quotent 0 done, print buffer  je end  jmp addbuf   addbuf:   add r8,r9         ;mov current location in our buffer   add rdx,0x30 ;  add r8,r10   mov [r8],rdx      ;mov last number in our buffer rdx   dec r9   inc r10   jmp start   end:   add r8,r9          ;add last digit  mov [r8],rdx  inc r10   mov rax,1  mov rdi,1  mov rsi,r8  mov rdx,r10  syscall   ret  _start:  mov rax,55  call printdec   mov rax,60  mov rdi,0  syscall  section .bss  letter: resb 1  number: resb 19 

printdec:  lea r9, [number + 18] ; last character of buffer  mov r10, r9         ; copy last character address  mov rbx, 10         ; base10 divisor   div_by_10:   xor rdx, rdx          ; 0 rdx div  div rbx            ; rax:rdx = rax / rbx  add rdx, 0x30      ; convert binary digit ascii  test rax,rax          ; if rax == 0 exit div_by_10  jz last_remainder  mov byte [r9], dl       ; save remainder  sub r9, 1               ; decrement buffer address  jmp div_by_10   last_remainder:   test dl, dl       ; if dl (last remainder) != 0 add buffer  jz check_buffer  mov byte [r9], dl       ; save remainder  sub r9, 1               ; decrement buffer address   check_buffer:   cmp r9, r10       ; if buffer has data print  jne print_buffer   mov byte [r9], '0' ; place default 0 empty buffer  sub r9, 1   print_buffer:   add r9, 1          ; address of last digit saved buffer  sub r10, r9        ; end address minus start address  add r10, 1         ; r10 = length of number  mov rax, 1         ; nr_write  mov rdi, 1         ;     stdout  mov rsi, r9        ;     number buffer address  mov rdx, r10       ;     string length  syscall   ret 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -