0

I have written out a small assembly program that divides two numbers, then displays the results through C printf function. The program asks for user input for the numbers, then does division as so:

mov rax, r14 ;r14 holds the numerator
cqo
mov rbx, r13 ;r13 holds the divisor
idiv rbx
mov r12, rax ;place divided answer into r12
mov r11, rdx ;place remainder from rdx into r11

Later printing out the values with:

mov rax, 0
mov rdi, outputresult ;outputresult defined as "The quotient of %ld divided by %ld is %ld with remainder %ld."
mov rsi, rsp
mov rsi, r14
mov rdx, rbx
mov rcx, r12
mov r8, r11
call printf

As is evident, I moved all values into their respective "calling" register to display the values correctly. This functions perfectly, except when the divisor (r13) is a negative number, I get the error stated before (Trace/breakpoint trap (core dumped).

The program continues to run regardless, and actually displays the correct values no matter if the divisor is negative or positive. However, I wish to get rid of the error which always appears right before the program finishes running. I can provide any further code if I am missing anything crucial.

lawgik
  • 87
  • 3
  • 10

2 Answers2

0

I have found the solution. To summarize, I initially pushed r14 as a qword by doing push qword r14 after saving the user's input into r14.

What I did to fix the issue, was do push qword 0 to avoid pushing r14 as a qword (which I assumed to be interfering with the cqo instruction), then proceeded to pop r14 after call scanf when collecting the user's input. Lastly, after mov rax, r14 was performed, cqo seemed to function perfectly well seeing as how I no longer received the error with a negative divisor.

lawgik
  • 87
  • 3
  • 10
-1

Run the program with a normal user.. I was Installing a Software and got the same error "(Trace/breakpoint trap (core dumped)". I was running the program using root user and It was failing and giving that error. then I searched on the Internet and got no working solution. then I ran it using a normal system user and It worked for me :)

Hope this helps

Thanks!!