piso_mojado 0 Newbie Poster

Hi,

I am new to the world of assembly and am trying to understand the flags and interpretation between an asm file and my cpp code. I basically have an asm function called by cpp file that runs a divide routine and am dereferencing to return parameter value for pointer:

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;
    }

and here is my asm file function:

_Divide    proc

        mov eax, [esp+4]
        mov ebx, [esp+8]
        cdq
        idiv ebx
                        
        mov ecx, [esp+12]    ;dereference to ecx
        mov ebx, 0
        cmp ecx, ebx
        jnz NotZero
                
        mov [ecx], edx        ;set remainder as value
        ret
NotZero:
        mov [ecx], edx        ;set remainder as value
        ret    
_Divide    endp

The idiv is working as expected and the &result value returns zero parameter when there is a zero remainder, but I can not determine how the flag is set for the while loop to see that &Remainder is zero and stop looping. I tried CMP to set zero flag, Tried setting explicit zero values, etc. and no dice!

Thanks for any insight in advance!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.