Skip to content

Instantly share code, notes, and snippets.

@lucansky
Created January 18, 2014 22:41
Show Gist options
  • Save lucansky/8497812 to your computer and use it in GitHub Desktop.
Save lucansky/8497812 to your computer and use it in GitHub Desktop.
Assembly exercise 7 - FPU x86
;**************************************************************
;
; Program HelloWorld - IAS
; FIT VUT v Brne
;
;**************************************************************
; Preklad programu lze provest nasledovne:
; nasm -fobj helloworld.asm
; alink -oPE -subsys console helloworld.obj
; nebo pomoci davky run.bat:
; run.bat hello
;**************************************************************
%include 'rw32.inc' ; nacteni knihovny rw32.inc
%include 'Win32_API.inc'
[segment .data use32] ; definice zacatku datoveho segmentu
; testovaci retezec
sMessage db "Cvicenie 5",10,13,0
;sArray dd 5,12,45,65,21
;sArray_size dd 5
x dq 0.2
negate dq -1.0
increment dq 1.0
result resq 1
[segment .code use32] ; definice zacatku kodoveho segementu
prologue ; makro -- inicializace programu
;mov esi,sMessage
;call WriteString
;FLD qword [a] ; st0 = a
;FLD qword [b] ; st0 = b; st1 = a
;FADD ; vacsinou pracuju s st0
;FADD st1 ; vysledok ulozi do st0 ; st0=b+a ; st1=a
;FABS ; st0=|st0| ; st1 = a
;FSIN ; st0=sin(|b+a|)
;FSQRT ; st0=sqrt(sin(|b+a|))
;call WriteDouble
FLD qword [x] ; st0 = x
FSIN ; st0=sin(x)
FMUL st0, st0 ; st0=sin2(x)
FMUL qword [negate] ; st0=-sin2(x)
FADD qword [increment] ; st0=-sin2(x)+1
FSQRT ; st0=sqrt(-sin2(x)+1)
FLD qword [x]
FCOS
FABS
FMUL qword [negate]
FADD st1
;call WriteDouble
FST qword [result]
call ReadDouble
;FTST ; porovnava s 0
FCOM st1 ; st0 s reg/mem
;FTST ; st0 ><= -> stavove reg c0, c1, c2, c3
; Flags to word
;FSTSW ax
; store AH to Flags
;SAHF
;ja , jb
;FTST
FSTSW ax
SAHF
jae .input_ge
.input_l:
FLD qword [result]
call WriteDouble
jmp .if_end
.input_ge:
call WriteDouble
.if_end:
epilogue ; makro -- ukonceni programu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment