-1

I have this assignment, and x, y, and z are double type variables:

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

Translating this into C, I got this:

z+= x*y

I am not sure about z tho? Did I translated it correctly? Thanks, any help appreciated.

Jester
  • 56,577
  • 4
  • 81
  • 125
Anastasia Netz
  • 173
  • 2
  • 12
  • No, I have tried to download some compilers that support assembly, but it seems like it requires the whole code, not a piece. I couldn't figure out how to test piece of code :( – Anastasia Netz Dec 09 '15 at 15:27
  • https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html – Eugene Sh. Dec 09 '15 at 15:30
  • Which compiler would you suggest tho? – Anastasia Netz Dec 09 '15 at 15:37
  • Evidently you are uncertain about the the effect of the assembly code or about the effect of the C code (or both). It's not apparent which. It might help you to write a detailed natural-language description of (what you think is) the effect of the code in question. – John Bollinger Dec 09 '15 at 15:37
  • It depends on your platform, but in general all the mainstream compilers support it. For Windows that would be MSVC, for Linux GCC or Clang (all free(ware)). And yes, I believe you have understood these instructions correctly. – user4520 Dec 09 '15 at 15:39
  • Ok so we pushing x into st(0), then we pushing y into st(0), and x goes into st(1). Then we multiply st(0) and st (1) hence x*y, and it goes into st(0). After that we pushing z into st(0) and x*y goes to st(1). Then we adding z to x*y, and moving it all in st(0), and then we pop the value off the stack - (fstpl). – Anastasia Netz Dec 09 '15 at 15:45

1 Answers1

3

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. 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.

Jester
  • 56,577
  • 4
  • 81
  • 125