Here are my questions,
- How do I store the remainder from edx back at the memory address of the third parameter?
- Do I need to use a subroutine in order to do so?
- What is the most efficient way to do so?
If you could show the correct code for this or a detailed explanation of how to that would be great. If you could show a combination of the two that would be excellent.
Here is my .asm file:
.386
.model flat
public _Divide
.code
_Divide proc
push ebp
mov ebp, esp
mov eax, [ebp + 8]
mov ebx, [ebp + 12]
cwd
idiv ebx
mov ecx, [ebp + 16]
cmp ecx, 0
jne remainder
jmp done
remainder:
mov [ebp + 16], edx ;this is showing as the minimum value for a
;long in the cpp(-860,000,000)
done:
pop ebp
ret
_Divide endp
end
Here is the .cpp file from which I am calling the _Division function:
#include <iostream>
using namespace std;
extern "C" long Divide (long, long, long *);
void main ()
{
long Result;
long Remainder;
long Dividend;
long Divisor;
do
{
cout << "Enter Dividend" << endl;
cin >> Dividend;
cout << "Enter Divisor" << endl;
cin >> Divisor;
Result = Divide (Dividend, Divisor, &Remainder);
cout << "Result is " << Result << " and Remainder is " << Remainder << endl;
} while ((Result >= 0) || (Remainder != 0));
Result = Divide (Dividend, Divisor, 0);
cout << "Result is " << Result << " and Remainder is not used" << endl;
}