From eedcd970e503c0bf72ec1a1af5e6995752f47e0e Mon Sep 17 00:00:00 2001 From: julianb0 Date: Thu, 13 Jun 2019 15:47:20 +0200 Subject: [PATCH] more doc --- vm/in/INSTRS | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- vm/in/arith.c | 22 +++------------------- vm/in/flags.h | 9 +++++++++ vm/in/string.c | 18 ++++++++++++++++++ 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/vm/in/INSTRS b/vm/in/INSTRS index 66d5bea..046c98a 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -206,7 +206,7 @@ div2 rim #---------------------------------------------------------------------------# # -# TEST Comparaison instruction +# TEST Comparison instruction # # $1 AND $2 # @@ -216,7 +216,7 @@ div2 rim test rim rim # -# CMP Comparaison instruction +# CMP Comparison instruction # # $1 - $2 # @@ -416,6 +416,50 @@ lodsb lodsb r lodsb rm r +# +# Scan string for a particular value (SCASx) +# +# CMP([%str], $val) +# +# IF (DF == 0) THEN +# %str = %str + sizeof(x) +# ELSE +# %str = %str - sizeof(x) +# FI +# +# Sets CF, OF, ZF and SF according to the result of the comparison +# +# When no parameters are given, %str = RDI and $val = RAX +# When one parameter is given, %str = RDI and $val = $1 +# When two parameters are given, %str = $1 and $val = $2 +# +scasb +scasb rim +scasb r rim + +# +# Compare bytes in strings (CMPSx) +# +# CMP([%str1], [%str2]) +# +# IF (DF == 0) THEN +# %str1 = %str1 + sizeof(x) +# %str2 = %str2 + sizeof(x) +# ELSE +# %str1 = %str1 - sizeof(x) +# %str2 = %str2 - sizeof(x) +# FI +# +# Sets CF, OF, ZF and SF according to the result of the comparison +# +# When no parameters are given, %str1 = RDI and %str2 = RSI +# When one parameter is given, %str1 = RDI and %str2 = $1 +# When two parameters are given, %str1 = $1 and %str2 = $2 +# +cmpsb +cmpsb r +cmpsb r r + # # Move value from string to string (MOVSx) # diff --git a/vm/in/arith.c b/vm/in/arith.c index f190ea5..99e05c5 100644 --- a/vm/in/arith.c +++ b/vm/in/arith.c @@ -100,32 +100,17 @@ IMPL_OUT; IMPL_START_2(subf) { - if (v1 < v2) flg |= CF; - else flg &= ~CF; - - if ( ((v2 < 0) && (v1 > LONG_MAX + v2)) - || ((v2 > 0) && (v1 < LONG_MIN + v2)) ) - flg |= OF; - else flg &= ~OF; - + COMPARE(v1, v2); v1 -= v2; } -IMPL_OUT_ZSF; +IMPL_OUT; // // i_subf but discards result // IMPL_START_2(cmp) { - if (v1 < v2) flg |= CF; - else flg &= ~CF; - - if ( ((v2 < 0) && (v1 > LONG_MAX + v2)) - || ((v2 > 0) && (v1 < LONG_MIN + v2)) ) - flg |= OF; - else flg &= ~OF; - - SET_ZSF(v1 - v2); + COMPARE(v1, v2); } IMPL_END; @@ -180,7 +165,6 @@ IMPL_START_2(mulf) } IMPL_OUT; - IMPL_START_1(mul2) { multiply(rax, v1, &rdx, &rax); diff --git a/vm/in/flags.h b/vm/in/flags.h index ecbe3e2..c99843c 100644 --- a/vm/in/flags.h +++ b/vm/in/flags.h @@ -21,3 +21,12 @@ SET_SF(v); \ SET_PF(v) +#define COMPARE(v1, v2) \ + if (v1 < v2) flg |= CF; \ + else flg &= ~CF; \ + if ( ((v2 < 0) && (v1 > LONG_MAX + v2)) \ + || ((v2 > 0) && (v1 < LONG_MIN + v2)) ) \ + flg |= OF; \ + else flg &= ~OF; \ + SET_ZSF(v1 - v2); + diff --git a/vm/in/string.c b/vm/in/string.c index f355502..91ca0fa 100644 --- a/vm/in/string.c +++ b/vm/in/string.c @@ -10,11 +10,29 @@ IMPL_START_0(stosb) } IMPL_END; +//----------------------------------------------------------------------------// + IMPL_START_0(lodsb) { } IMPL_END; +//----------------------------------------------------------------------------// + +IMPL_START_0(scasb) +{ +} +IMPL_END; + +//----------------------------------------------------------------------------// + +IMPL_START_0(cmpsb) +{ +} +IMPL_END; + +//----------------------------------------------------------------------------// + IMPL_START_0(movsb) { }