如何在汇编中乘以 2^n? [英] How to multiply by 2^n in assembly?

查看:26
本文介绍了如何在汇编中乘以 2^n?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定 2 个数字,x 和 n,将 x 乘以 2^n 的方法是什么?例如 x=3.7 和 n=5.所以 3.7*2^5 = 118.4.我需要在不使用 FPU 命令(数学协处理器)的情况下完成此操作.

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).

所以我认为 32 bt 处理器中的数字由 32 位表示:第一个是符号,接下来的 8 (2-9) 个是指数,接下来的 23 个被称为 SIGNIFICAND.

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.

指数字段是 2^k 中的 k.所以我需要做的只是改变指数字段并将 n 添加到它.exponent = exponent + n .

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 .

那么我如何在程序集 8086 中执行此操作?

So how do i do this in assembly 8086 ?

谢谢

推荐答案

这里有一些非常丑陋的内联汇编,VS 风格.希望你能明白:

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

这显然不检查溢出等

这篇关于如何在汇编中乘以 2^n?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆