From 53ccfab6c1f2ddad977ceedbdbbfa54a05b81070 Mon Sep 17 00:00:00 2001 From: exegete Date: Sat, 17 Oct 2020 17:52:20 +0300 Subject: stack print and etc --- common/common.sts | 1 + common/print.sts | 30 ++++++++++++++++++++++++++++++ ia32/bitwise.sts | 21 +++++++++++++++++++++ ia32/float/float.sts | 20 +++++++++++++++----- test.sts | 17 +++++++++++++---- 5 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 common/print.sts diff --git a/common/common.sts b/common/common.sts index cc5f5ee..8a7f835 100644 --- a/common/common.sts +++ b/common/common.sts @@ -1,2 +1,3 @@ module common/macro.sts module common/const.sts +module common/print.sts diff --git a/common/print.sts b/common/print.sts new file mode 100644 index 0000000..9517307 --- /dev/null +++ b/common/print.sts @@ -0,0 +1,30 @@ +defword get_hex + f and + dup 9 > if + a - 'a' + + else + '0' + + fi +exit + +defword print_hex + dup 1c shr get_hex sys_write + dup 18 shr get_hex sys_write + dup 14 shr get_hex sys_write + dup 10 shr get_hex sys_write + dup c shr get_hex sys_write + dup 8 shr get_hex sys_write + dup 4 shr get_hex sys_write + get_hex sys_write + a sys_write +exit + +defword print_stack + dup + do + dup 0 = until + over over - 2 + get print_hex + 1 - + od + drop +exit diff --git a/ia32/bitwise.sts b/ia32/bitwise.sts index b86e6c6..205e618 100644 --- a/ia32/bitwise.sts +++ b/ia32/bitwise.sts @@ -4,3 +4,24 @@ defasm xor # 31 ?' # d8 ?' ; xor eax, ebx # 50 ?' ; push eax next + +defasm and + # 5b ?' ; pop ebx + # 58 ?' ; pop eax + # 21 ?' # d8 ?' ; and eax, ebx + # 50 ?' ; push eax +next + +defasm shr + # 59 ?' ; pop ecx + # 58 ?' ; pop eax + # d3 ?' # e8 ?' ; shr eax, cl + # 50 ?' ; push eax +next + +defasm shl + # 59 ?' ; pop ecx + # 58 ?' ; pop eax + # d3 ?' # e0 ?' ; shl eax, cl + # 50 ?' ; push eax +next diff --git a/ia32/float/float.sts b/ia32/float/float.sts index 158781c..9f3ba52 100644 --- a/ia32/float/float.sts +++ b/ia32/float/float.sts @@ -3,6 +3,21 @@ defasm float_init # 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 @@ -23,11 +38,6 @@ defasm float_istore # db ?' # 1c ?' # 24 ?' ; fistp dword [esp] next -defasm float_status - # de ?' # f9 ?' ; fnstsw ax - # 50 ?' ; push eax -next - defasm float_add # de ?' # c1 ?' ; faddp st1, st0 next diff --git a/test.sts b/test.sts index 9158c49..896400e 100644 --- a/test.sts +++ b/test.sts @@ -3,14 +3,23 @@ module ia32/float/float.sts set_entry float_init +21 float_iload +4 float_iload +21 float_iload +4 float_iload 8 float_iload -3 float_iload -float_div -float_istore '0' + sys_write +0 float_iload 21 float_iload 4 float_iload float_div -float_istore '0' + sys_write +float_istore +float_div +float_istore +float_div +float_istore +float_div +float_istore +7 print_stack sys_exit module ia32/elf/end.sts -- cgit v1.2.3