【问题标题】:Assembly 8086: Two Float Point[32bit] Adding,Sub etc程序集 8086:两个浮点 [32 位] 加法、减法等
【发布时间】:2012-12-22 08:29:22
【问题描述】:

我需要在 8086 中添加两个浮点数

    12.3 ---> 4144 CCCDh
    (AX,BX) = (4144h, CCCDh)

我需要添加任何数字,这个浮点数看起来像:

    (AX,BX) = (AX,BX) + 10h

如果我这样做,答案是错误的。

     (AX,BX) + 10h == 4144 CCECh

但是 23,3 不等于 4144 CCECh

你能帮帮我吗?我如何添加这两个数字?

【问题讨论】:

  • 你真的有8086吗?如果是这样,还有一个8087?那会做浮点更好。无论如何,请向我们展示您的一些代码。
  • 我是组装新手,我使用emu 8086进行编码。这是我的测验问题,我不知道如何添加这两个数字。

标签: assembly floating-point 32-bit x86-16


【解决方案1】:

尚未验证这一点(尤其是 bp 中的偏移量),但它应该提供一些观点。 它使用了古老的8087 floating point instruction set

所有操作都发生在协处理器堆栈和/或内存之间。可以使用指令FILD mem 将整数从 2 的补码表示转换,并且在某些情况下,有一个内置的加法指令将整数(从内存中)添加到 FP 寄存器。

 push bp
 mov bp, sp
 push bx
 push ax
 push word ptr 10   ;  // decimal, not hex
 fld dword ptr [bp] ;   load float (just pushed from bx,ax)
 fiadd word ptr [bp-4] ;   add the integer in stack
 fst dword ptr [bp] ;   store result
 pop ax             
 pop ax             ; restore the high word of result
 pop bx             ; restore low word
 pop bp             ; restore frame pointer

【讨论】:

    【解决方案2】:

    您不能像这样将整数 (10) 添加到 IEEE-754 浮点值 (12.3f = 0x4144cccd)。您需要将 10 表示为 IEEE-754 格式(10.0f = 0x41200000),然后使用浮点加法指令。

      0x4144cccd      12.3
    + 0x41200000    + 10.0
      ----------      ----
      0x41B26666      22.3
    

    【讨论】:

    • 谢谢,但是我如何给这个值在 8086 中注册你能帮忙吗?
    • 如果它真的是一个古老的 8086,那么你需要一个 8087 协处理器或一个软件 FPU 仿真。要么这样,要么你必须自己编写一些浮点例程。
    猜你喜欢
    • 2021-04-24
    • 1970-01-01
    • 2021-12-14
    • 2015-10-03
    • 2011-12-14
    • 2020-03-09
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多