assemblyx86x87

assembly x86 x to the power of b


I have a problem with a program that does x^b. It works but stack is not empty.

#include <iostream>
using namespace std;
int main()
{
    float a = 1, b = 4, c = 1, d = 1, x = 2, y;
    __asm {
        fld x;
        fld b;
        fyl2x;
        fld st;
        fprem;
        f2xm1;
        fld1;
        fadd;
        fscale;  
        fstp y;
    }
    cout << y;
}

Solution

  •         fld b;
            fld x;
            fyl2x;
            fld st;
            frndint;
            fsub st(1),st;
            fxch;
            f2xm1;
            fld1;
            fadd;
            fscale;
            fstp st(1);
            fstp y