Home > Blockchain >  GNU assembler is not giving the proper floating point value
GNU assembler is not giving the proper floating point value

Time:12-21

I am trying to write the following code:

.data
float_val: .float 0e122.23
.text
.global _start
_start:
fldl float_val
mov $60,%rax
xor %rdi,%rdi
syscall

After using gdb, the value in st(0) is some garbage. Why so? I am not understanding where the problem is. A YASM counterpart is working correctly.

CodePudding user response:

According to the GAS manual, the mnemonic suffixes are different for floating-point instructions than for integer. Integer instructions use the l suffix for a 32-bit dword; but for floating-point instructions, l is for a 64-bit double. You use s for a 32-bit single-precision float. So write flds float_val and it should work.

  • Related