如何在程序集x8086中打印80位双精度扩展浮点数?

时间:2019-05-16 14:51:27

标签: assembly x86

我正在做作业,并且想通过printf打印一个80位的双精度扩展数字。该数字是由某些缩放函数计算的,使用gdb可以看到计算出正确数字的能力。我使用在bss节中定义为var1的一些指针指向10字节的块,即:var1:rest 1 然后var1指向内存中10个字节的块。

到目前为止,我尝试将10个字节压入堆栈,然后以%f或%lf格式打印数字,但都无法打印该数字,我也注意到使用qword并将4个字节压入堆栈两次(部分个数字效果很好),但我需要使用第二个定义。


scale_number:
  push ebp                  ;; Pushing Base pointer (contains address of current activation frame
                            ;; which is actually the return address of the caller) to the stack

  mov ebp, esp              ;; Overrides ebp value to Stack pointer's value which contains the
                            ;; address of last used dword in the stack.

  pushad                    ;; Push all significant registers (8 general purpose registers)
                            ;; onto the stack (backup registers values)

  mov ebx, [ebp + 12]       ;; Upper bound
  sub dword ebx, [ebp + 8]  ;; Substruct ebx with the Lower bound
  mov ecx, [ebp + 16]       ;; get the pointer of the result contianer

  finit

  mov eax, dword [seed]
  mul ebx
  push eax
  fild dword [esp]
  add esp, 4
  push 0x0000FFFF
  fidiv dword [esp]
  add esp, 4
  fiadd dword [ebp + 8]
  fstp tword [ecx]

  ffree

  popad
  return_from_function ; macro for quiting the function

现在ecx指向var1

其余代码:


  push dword var1
  push 100
  push 40

  call scale_number

  ;; Floating point tester TWORD
  sub esp, 10
  mov ebx, 0
  .loop4:
    mov eax, [var1 + ebx]
    mov [esp + ebx], eax
    inc ebx
    cmp ebx, 10
    jne .loop4

  push format_fp ;; using "%f" , 10, 0 as the format_fp
  call printf
  add esp, 14

  jmp exit

我的输出是-0.000000,但是我的预期输出是80。..

0 个答案:

没有答案