Assembly 如何在部件x8086中打印80位双扩展精度浮点数?
我正在做家庭作业,想通过printf打印一个80位的双精度扩展数字。这个数字是通过一些缩放函数计算出来的,我看到它使用gdb计算出了正确的数字。我使用在bss部分中定义为:var1:rest1的名为var1的指针指向10个字节的块 然后var1指向内存中一个10字节的块 到目前为止,我试图将10个字节放入堆栈,然后用格式%f或%lf打印数字,但都无法打印数字,而且我注意到使用qword并将4个字节两次放入堆栈(部分数字工作正常),但我需要使用tword定义Assembly 如何在部件x8086中打印80位双扩展精度浮点数?,assembly,x86,Assembly,X86,我正在做家庭作业,想通过printf打印一个80位的双精度扩展数字。这个数字是通过一些缩放函数计算出来的,我看到它使用gdb计算出了正确的数字。我使用在bss部分中定义为:var1:rest1的名为var1的指针指向10个字节的块 然后var1指向内存中一个10字节的块 到目前为止,我试图将10个字节放入堆栈,然后用格式%f或%lf打印数字,但都无法打印数字,而且我注意到使用qword并将4个字节两次放入堆栈(部分数字工作正常),但我需要使用tword定义 现在ecx指向var1 代码的其余部
现在ecx指向var1 代码的其余部分:
我的输出是-0.000000,但我的预期输出是80。有些东西..
子esp,10
非常糟糕。您应该始终保持至少4字节对齐。可能与你的问题无关,只是说说而已。对于80位的值,请尝试使用大写字母%Lf
。另外,请参阅您的libc手册。它可以工作,打印80.466926。你能进一步解释一下子esp吗,10非常糟糕。您应该始终保持至少4字节的对齐Stack指针必须是4的倍数(在某些调用约定下,甚至是16)。10不是4的倍数,因此假设堆栈指针在此之前已对齐,则之后将未对齐。分配12个字节,即使只需要10个字节。在16字节对齐要求的情况下,你必须考虑你的整个函数。你可以使用<代码> FBSTP < /代码>作为一个快速和肮脏的转换例程。
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
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