0

So I have been trying to print digits in x64 assembly nasm program and my source code is this:

section .data digit: db 0, 10 section .text global _start _start: mov rax, 6 mov rbx, 2 div rbx call _printRAXDigit mov rax, 60 mov rdi, 0 syscall _printRAXDigit: add rax, 48 mov [digit], al mov rax, 1 mov rdi, 1 mov rsi, digit mov rdi, 2 syscall ret 

But the output is empty and nothing appears. Is there a problem with my code or assembler

UPDATE: CherryDT found the answer it was that I typed rdi instead rdx

2
  • 1
    Yes, you accidentally typed rdi a second time instead of rdx (so you wrote an undefined number of characters depending on previous contents of rdx - probably zero - to stderr, i.e. FD 2, instead of printing 2 characters to stdout). I recommend learning how to use a debugger, you could then easily observe that this is happening if you break on the syscall and check the registers. Commented Apr 16, 2022 at 12:20
  • Use strace ./a.out to see what args you pass to system calls. e.g. that you passed length = 0 (the remainder from div, which didn't fault since this is presumably built into a static executable so RDX was zero before the division as well). Basic debugging would have caught this typo, closing as a duplicate mostly as a typo. Commented Apr 16, 2022 at 12:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.