assembly - 如何在汇编 x8086 中打印 80 位双扩展精度浮点数?
问题描述
我正在做一个家庭作业,并想通过 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. 东西..
解决方案
推荐阅读
- timestamp - Azure 数据工厂、复制数据、Teradata ODBC、日期时间时间戳映射
- reactjs - React Native:如何显示特定类别的帖子?
- python - 如何通过 BeautifulSoup 打印波斯语页面的文本?
- flutter - Flutter:当前 Flutter SDK 版本为 0.0.0-未知
- google-colaboratory - /bin/bash: ./darknet: No such file or directory 问题
- java - 为什么在迭代 HashMap 时在 IF 块中添加元素会起作用?
- arrays - 如何检查数组中元素的位置?
- apache-kafka - KTable-KTable 外键连接语义
- ansible - Ansible 用户模块:如何将 UID 定义为默认设置?
- sqlite - 按时间戳分组 sqlite3