x86_64-linux-asm/float/hello.asm

56 lines
1.2 KiB
NASM

default rel ; make [rel format] the default, you always want this. idk why i always want this but im taking it anyway
extern puts
extern printf
section .data
text db "Bottom Text",0
val dq 123.45
section .bss
res resq 1 ; reserve 1 quadword for result
section .rodata
format db "%#f", 10, 0 ; C 0-terminated string: "%#x\n" idk why this is in its own section im just stealing code
section .text
global main
main:
sub rsp, 8 ;this is needed because im using "C"
; load value into st(0)
fld qword [val] ; treat val as an address to a qword <it has to know that its a qword i think idk this shit is scary>
; compute square root of st(0) and store the result in st(0)
fsqrt ;<so like the fpu has like its own registers that cant be used with mov and they act as a stack or somthing and its fucking scary help me>
; store st(0) at res, and pop it off the x87 stack
fstp qword [res]
; the FPU stack is now empty again
mov rdi, res
cld
call puts ;this is the puts way of printing a string
mov esi, res
lea rdi, [rel format]
cld
call printf
_end:
add rsp, 8
ret
; mov rax, 60 ; exit
; mov edi, 1 ; error 1 dont need the exit anymore beacue libc or somthing
; syscall