Domanda

Given 2 numbers, x and n, what's the method to multiply x by 2^n ? For instance x=3.7 and n=5. so 3.7*2^5 = 118.4. I need this done without using the FPU commands (math coprocessor).

So i figured that numbers in 32 bt processor are represented by 32 bits: the 1st is for the sign, next 8 (2-9) are for the exponent, and the following 23 are called the SIGNIFICAND.

The exponent field is the k in 2^k. So what i need to do is only change the exponent field and add n to it. exponent = exponent + n .

So how do i do this in assembly 8086 ?

Thank you

È stato utile?

Soluzione

Here's some quite ugly inline asm, VS style. Hopefully you'll get the idea:

float mul(float f, int p)
{
    __asm {
        mov eax, f
        mov ecx, p
        shl ecx, 23
        add eax, ecx
        mov f, eax
    }

    return f;
}

This obviously does no checking for overflow, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top