0

I trying add two large integers numbers, but the ouput show it in ASCII, how can i print a integer value?

Here is the main code:

section .bss
    res: resq 8
sum:
    mov rax,rdi
    add rax,rsi
    add rax,'0'
    ret  

_start:             ;tells linker entry point
   mov rdi,'100'
   mov rsi,'102'
   call sum
   mov [res],rax

   mov  rdx,3     ;message length
   mov  rsi,res  ;message to write
   mov  rdi,1       ;file descriptor (stdout)
   mov  rax,1       ;system call number (sys_write)
   syscall
   mov  rax,60       ;system call number (sys_exit)
   syscall

The ouput: �`

LordPaella
  • 143
  • 9
  • 2
    You'll have to convert the number into a string that can be printed. There are already plenty of questions about how to do that. Also, why are you using `'100'` and `'102'` instead of `100` and `102`? – Michael Dec 15 '18 at 18:40
  • I change it and now the output is '�', can you link the post? – LordPaella Dec 15 '18 at 18:44
  • You should look at this answer from a related SO question: https://stackoverflow.com/a/46301894/3857942 .Part of me wants to make this a duplicate of that. – Michael Petch Dec 15 '18 at 18:55
  • `mov edx, 3` and `mov edi, 1; mov eax, edi` would be shorter – phuclv Dec 16 '18 at 01:32

0 Answers0