From be953c23a9ee9c328d186e0afd7fbc0855eefd3a Mon Sep 17 00:00:00 2001 From: exegete Date: Sat, 17 Oct 2020 20:59:23 +0300 Subject: float lib finished --- ia32/float/control.sts | 19 +++++++++++++++++++ ia32/float/float.sts | 50 +++----------------------------------------------- ia32/float/math.sts | 32 ++++++++++++++++++++++++++++++++ ia32/float/stack.sts | 19 +++++++++++++++++++ test.sts | 20 +++----------------- 5 files changed, 76 insertions(+), 64 deletions(-) create mode 100644 ia32/float/control.sts create mode 100644 ia32/float/math.sts create mode 100644 ia32/float/stack.sts diff --git a/ia32/float/control.sts b/ia32/float/control.sts new file mode 100644 index 0000000..3863f5f --- /dev/null +++ b/ia32/float/control.sts @@ -0,0 +1,19 @@ +defasm float_init + # 9b ?' ; wait + # db ?' # e3 ?' ; fninit +next + +defasm float_cload + # d9 ?' # 2c ?' # 24 ?' ; fldcw [esp] + # 58 ?' ; pop eax +next + +defasm float_sstore + # 9b ?' # df ?' # e0 ?' ; fstsw ax + # 50 ?' ; push eax +next + +defasm float_cstore + # 50 ?' ; push eax + # d9 ?' # 3c ?' # 24 ?' ; fstcw [esp] +next diff --git a/ia32/float/float.sts b/ia32/float/float.sts index 9f3ba52..d6907ca 100644 --- a/ia32/float/float.sts +++ b/ia32/float/float.sts @@ -1,47 +1,3 @@ -defasm float_init - # 9b ?' ; wait - # db ?' # e3 ?' ; fninit -next - -defasm float_cload - # d9 ?' # 2c ?' # 24 ?' ; fldcw [esp] - # 58 ?' ; pop eax -next - -defasm float_sstore - # 9b ?' # df ?' # e0 ?' ; fstsw ax - # 50 ?' ; push eax -next - -defasm float_cstore - # 50 ?' ; push eax - # d9 ?' # 3c ?' # 24 ?' ; fstcw [esp] -next - -defasm float_fload - # d9 ?' # 04 ?' # 24 ?' ; fld dword [esp] - # 58 ?' ; pop eax -next - -defasm float_iload - # db ?' # 04 ?' # 24 ?' ; fild dword [esp] - # 58 ?' ; pop eax -next - -defasm float_fstore - # 50 ?' ; push eax - # d9 ?' # 1c ?' # 24 ?' ; fstp dword [esp] -next - -defasm float_istore - # 50 ?' ; push eax - # db ?' # 1c ?' # 24 ?' ; fistp dword [esp] -next - -defasm float_add - # de ?' # c1 ?' ; faddp st1, st0 -next - -defasm float_div - # de ?' # f9 ?' ; fdivp st1, st0 -next +module ia32/float/control.sts +module ia32/float/stack.sts +module ia32/float/math.sts diff --git a/ia32/float/math.sts b/ia32/float/math.sts new file mode 100644 index 0000000..9be8712 --- /dev/null +++ b/ia32/float/math.sts @@ -0,0 +1,32 @@ +defasm float_add + # de ?' # c1 ?' ; faddp st1, st0 +next + +defasm float_sub + # de ?' # e9 ?' ; fsubp st1, st0 +next + +defasm float_mul + # de ?' # c9 ?' ; fmullp st1, st0 +next + +defasm float_div + # de ?' # f9 ?' ; fdivp st1, st0 +next + +defasm float_sqrt + # d9 ?' # fa ?' ; fsqrt +next + +defasm float_more + # de ?' # d9 ?' ; fcompp + # 9b ?' # df ?' # e0 ?' ; fstsw ax + # 25 ?' # 100 ?. ; and eax, 0x100 + # c1 ?' # e8 ?' # 8 ?' ; shr eax, 14 + # 50 ?' ; push eax +next + +defword float_less + float_more + 0 = +exit diff --git a/ia32/float/stack.sts b/ia32/float/stack.sts new file mode 100644 index 0000000..ca95196 --- /dev/null +++ b/ia32/float/stack.sts @@ -0,0 +1,19 @@ +defasm float_fload + # d9 ?' # 04 ?' # 24 ?' ; fld dword [esp] + # 58 ?' ; pop eax +next + +defasm float_iload + # db ?' # 04 ?' # 24 ?' ; fild dword [esp] + # 58 ?' ; pop eax +next + +defasm float_fstore + # 50 ?' ; push eax + # d9 ?' # 1c ?' # 24 ?' ; fstp dword [esp] +next + +defasm float_istore + # 50 ?' ; push eax + # db ?' # 1c ?' # 24 ?' ; fistp dword [esp] +next diff --git a/test.sts b/test.sts index be21ac0..1e96807 100644 --- a/test.sts +++ b/test.sts @@ -3,24 +3,10 @@ module ia32/float/float.sts set_entry float_init -21 float_iload 4 float_iload -21 float_iload -4 float_iload -8 float_iload -0 float_iload -21 float_iload -4 float_iload -float_div -float_istore -float_div -float_istore -float_div -float_istore -float_div -float_istore -7 print_stack -7 print_stack +5 float_iload +float_more +4 print_stack sys_exit module ia32/elf/end.sts -- cgit v1.2.3