Using x86 Assembly to Manipulate Floating Point Numbers with FPU but Getting NaN Results
I'm converting an old project and I'm reviewing some code and Does anyone know how to I'm getting frustrated with I'm working on an x86 assembly project where I need to perform some calculations with floating point numbers using the FPU... However, I'm working with a question where my results are coming back as NaN (Not a Number). I've tried a basic setup where I load two floating point numbers, add them, and then store the result. Hereβs the code snippet that I'm using: ```assembly section .data num1 dd 3.14 num2 dd 2.71 result dd 0.0 section .text global _start _start: ; Load num1 into ST(0) fld dword [num1] ; Load num2 into ST(0) fld dword [num2] ; Add ST(0) and ST(1) and store the result in ST(0) fadd ; Store the result in memory fstp dword [result] ; Exit code (Linux) mov eax, 1 xor ebx, ebx int 0x80 ``` After executing, I'm checking the `result` variable but it seems to hold NaN instead of the expected sum. To troubleshoot, I verified that the values in `num1` and `num2` are correct. I ensured that Iβm using the correct data types (32-bit float) and that the FPU is correctly initialized. I'm compiling this code using NASM and linking it on a Linux system. Iβve also tried checking the FPU status word, but Iβm not sure how to interpret it fully. Could there be an scenario with how I'm pushing and popping values onto the FPU stack? Or is there something specific I need to do to avoid NaN results? Any insights would be greatly appreciated! Any suggestions would be helpful. This is my first time working with Assembly stable. Could this be a known issue? The stack includes Assembly and several other technologies. I'm coming from a different tech stack and learning Assembly. Am I approaching this the right way?