; Ukol 2:
; Vypocitej a^2-c a sqrt(b)+c a vypis vetsi vysledne cislo
; Autor: Dominika Regeciova

%include "rw32-2018.inc"

section .data
a dd 8.0
b dd 25.0
c dd 3.0

bFormat db "%f",0

section .bss
    var resd 1

section .text

_main:

    finit               ; inicializace jednotky FPU

    fld dword [a]       ; st0 = a
    fmul st0            ; st0 = a^2
    fld dword [c]       ; st0 = c, st1 = a^2
    fxch                ; st0 = a^2, st1 = c 
    fsub st1            ; st0 = a^2 - c
    call WriteDouble
    call WriteNewLine
    fstp dword [var]    ; [var] = st0 + pop st0

    fld dword [b]       ; st0 = b
    fsqrt               ; st0 = sqrt(b)
    fld dword [c]       ; st0 = c, st1 = sqrt(b)
    fadd st1            ; st0 = sqrt(b) + c
    call WriteDouble
    call WriteNewLine

    fcom dword [var]    ; provnani a^2 - c a sqrt(b) + c
    fstsw ax            ; ulozi stavovy registr FPU do AX
    sahf                ; ulozeni c3,c2 a c0 do eflags
    
    jnc next           ; skok, pokud je sqrt(b) + c vetsi

    fld dword [var]     ; a^2 - c je vetsi

next:                   ; vypis vysledku z st0 pomoci funkce printf
    sub esp, 8
    fst qword [esp]
    push bFormat
    call printf
    add esp, 12
ret
