I am making a compiler that compiles to x86_64 assembly, and I am trying to implement floating point math. However, I soon ran into problems because floating points are a struggle in assembly, so I am trying to practice with them, but I am finding no luck.
In this program, I want to add two floats together, compare them with another float and print a message if they are equal, but nothing is being printed.
section .data
float1: dd 3.14
float2: dd 5.72
cmp_float: dd 8.86
msg: db "Is equal!", 10, 0
msg_len equ $-msg
section .bss
result: resd 1
section .text
global _start
_start:
fld dword [float1] ; Load float1 into FPU stack
fld dword [float2] ; Load float2 into FPU stack
faddp ; Add two top floats of the FPU stack and push back onto the FPU stack
fcomp dword [cmp_float] ; Compare with the top value of the FPU stack
fstsw ax ; Store FPU status word in AX register
sahf ; Move AH register to FLAGS register
je .equal
jmp .exit
.equal:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, msg_len
syscall
.exit:
mov rax, 60
mov rdi, 0
syscall