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.