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?
s
is 32 bit (float
),l
is 64 bit (double
).fstpl 4(%esp)
. I assume you are looking at unoptimized code.printf
expects arguments as per the C calling convention, so varargs are automatically promoted todouble
.