I am working on an assignment for my class. My C++ code calls the _Divide
function to take in 2 values to divide and return into 'Result'. To start I move -1 into eax. Once I'm done with the process, my eax keeps returning '-1' as the value. What could I be doing wrong? Here's my assem code:
public _Divide
.386
.model flat
.code
_Divide proc
mov eax, -1
mov ebx, 1
cdq
idiv ebx
ret
_Divide endp
end
Here's my C++ code
#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;
}
Thanks.