简体   繁体   English

x87浮点指令转换为C代码

[英]x87 floating point instructions into C code

I have this assignment, and x, y, and z are double type variables: 我有这个分配,并且x,y和z是双类型变量:

fldl    x
fldl    y
fmulp   st, st(1)
fldl    z
faddp   st, st (1)
fstpl   z

Translating this into C, I got this: 将其转换为C,我得到了:

z+= x*y

I am not sure about z tho? 我不确定z tho吗? Did I translated it correctly? 我翻译正确吗? Thanks, any help appreciated. 谢谢,任何帮助表示赞赏。

Yes, you got the meaning correctly figured out. 是的,您已经正确理解了含义。

For later reference, you can just stick such code into an assembly file and step through in a debugger. 供以后参考,您可以将此类代码粘贴到汇编文件中并逐步进入调试器。 From the at&t syntax I assume it is intended for gas , the gnu assembler. 从at&t语法中,我认为它适用于gnu汇编器gas You can test it like this: 您可以像这样测试它:

$ cat > test.s
.att_syntax noprefix
.globl _start
_start:
fldl    x
fldl    y
fmulp   st, st(1)
fldl    z
faddp   st, st (1)
fstpl   z
.data
x: .double 2
y: .double 3
z: .double 4
$ gcc -m32 -nostdlib -g test.s
$ gdb ./a.out
(gdb) b _start
Breakpoint 1 at 0x80480b8: file test.s, line 4.
(gdb) r
Starting program: /var/tmp/./a.out

Breakpoint 1, _start () at test.s:4
4       fldl    x
(gdb) s
5       fldl    y
(gdb)
6       fmulp   st, st(1)
(gdb)
7       fldl    z
(gdb)
8       faddp   st, st(1)
(gdb)
9       fstpl   z
(gdb)
0x080480d4 in ?? ()
(gdb) x/gf &z
0x80490e4:      10

Note I have added some test input at the end, and some needed stuff at the top. 注意,我在末尾添加了一些测试输入,并在顶部添加了一些需要的东西。

You can of course examine all registers during the execution at any point too, see gdb help for other commands. 当然,您也可以在执行过程中随时检查所有寄存器,有关其他命令,请参见gdb帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM