0

I'm trying to output the top value on the stack (here it is "6"). But I get garbage. Am I missing something ?

push rax
mov     rax, 1      ; 'write' syscall number
mov     rdi, 1      ; stdout descriptor
mov     rsi, rsp    ; rsp is the address where number "6" is stored by "push rax" before
mov     rdx, 1      ; string length
syscall
trogne
  • 3,402
  • 3
  • 33
  • 50
  • 2
    That looks correct. What exactly is in `rax`? Note you need text. If it's the value `6` that is a non-printable control character `ACK`. See [man ascii](https://man7.org/linux/man-pages/man7/ascii.7.html) – Jester Apr 27 '21 at 21:26
  • 1
    thanks! rax was holding 6, but should have been 54 (ascii code for character "6") – trogne Apr 27 '21 at 22:34
  • If you want for output an ASCII string of decimal digits that represent the number, you'll have to prepare that in a buffer, like in [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) – Peter Cordes Apr 28 '21 at 02:32

0 Answers0