0

I'm writing a small assembly program which takes two single-precision floating point numbers, adds them together and displays the result. However, I would like to have the result saved in a register for later use. To help me get started, I've compiled a c++ program into an assembly program, and tried to edit that. However, I don't understand the results I get, which are following:

    movl    $0x49742408, %eax
    movl    %eax, 20(%esp)
    movl    $0x49f42405, %eax
    movl    %eax, 24(%esp)
    flds    20(%esp)
    fadds   24(%esp)
    fstps   28(%esp)
    flds    28(%esp)
    fstpl   4(%esp)
    movl    $.LC2, (%esp)
    call    printf
    movl    $0, %eax

First, am I correct when regarding floats, that s means 32-bit and l means 64-bit? Second, why is it popping a 32-bit float value into 28(%esp), only to store it back into the data register stack? Removing these two lines results in a less precise result, which is odd. Lastly, it pops the data register stack again, but this time a 64-bit value. I would like a single precision 32-bit value. However, changing l to s results me in getting 0. Does anybody know what exactly is going on?

nrz
  • 10,435
  • 4
  • 39
  • 71
spurra
  • 1,007
  • 2
  • 13
  • 38

1 Answers1

0
  1. Yes, s is 32 bit (float), l is 64 bit (double).
  2. You can't just remove it of course, you then have to use fstpl 4(%esp). I assume you are looking at unoptimized code.
  3. printf expects arguments as per the C calling convention, so varargs are automatically promoted to double.
Jester
  • 56,577
  • 4
  • 81
  • 125
  • 2. Yes, it is unoptimized. So why does it do it? 3. How do I change it to a float? – spurra Nov 29 '13 at 16:29
  • As I said, `printf` only handles doubles as per the C standard. You can change it to a float, but then can't use `printf`. – Jester Nov 29 '13 at 17:17