; School of Computer Engineering
; K.N. Toosi University of Technology

%include "asm_io.inc"
extern printf
        
segment .data
a:       dq       1.0
b:       dq      -3.0
c:       dq       2.0
minus4:  dq      -4.0 
        
temp:    dq      0.0

format:  db   "%f", 10, 0
no_roots_msg: db "No real roots", 10, 0
        
segment .text
        global asm_main
        
asm_main:
        pusha

        fld  qword [b]
        fld  qword [b]
        fmulp ST1

        fld qword [a]
        fld qword [c]
        fld qword [minus4]
        fmulp ST1
        fmulp ST1

        faddp ST1

        
        fldz
        fcomip ST1
        ja     no_roots

        fsqrt

        fld st0                 ; stack: sqdelta, sqdelta

        fld qword [b]
        faddp st1
        fchs

        fld qword [a]
        fld1
        fld1
        faddp
        fmulp

        fdivp ST1               ; ST1 /= ST0

        ; print st0
        fst  qword [temp]
        push dword [temp+4]
        push dword [temp]
        push format
        call printf
        add  esp, 12

        fcomp

        fld qword [b]
        fchs
        faddp

        fld qword [a]
        fld1
        fld1
        faddp
        fmulp

        fdivp ST1               ; ST1 /= ST0



        ; print st0
        fst  qword [temp]
        push dword [temp+4]
        push dword [temp]
        push format
        call printf
        add  esp, 12

        jmp endl

        
no_roots:
        mov eax, no_roots_msg
        call print_string
endl:
        popa
        ret