1

I am unable to print text other than pre defined variables into the console. For example,

add dx, 48
mov rax, 1 
movzx rsi, dx
mov rdx, 1
syscall

somehow results in a "Floating point exception (core dumped)". Dx should be an integer from 0 to 9, and from what I understand which could very well be wrong adding 48 should make it the ascii form of 0 to 9 since 48 is the ascii value for '0'. Please help.

I tried narrowing down what went wrong by instead doing

mov rax, 1
mov rsi, 'test'
mov rdx, 4
syscall

which should've just printed "test", but instead it prints nothing which I have no clue why

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
suqayzsyz
  • 11
  • 2
  • `write(int fd, void *buf, size_t len)` takes a *pointer* to the data, not by value, so you're just passing invalid pointers to write, which will return `-EFAULT`. In your first example, none of the the instructions you show will raise a SIGFPE, including `syscall`. Perhaps that was part of a loop that used `div` to get digits, and the bug was in how you used `div`, causing an arithmetic exception (#DE) leading to SIGFPE. Run you code under GDB to see which instruction faulted. – Peter Cordes Mar 18 '23 at 05:47

0 Answers0