diff --git a/ka/main.k b/ka/main.k index ba7d567..eb1f473 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,7 +5,10 @@ ; Main function ; main: - call movzx_test + jmp bswap_test + +bswap_test: + mov rdx, 0xFFEEDDCCBBAA99884433 ret ramdev_test: diff --git a/vm/in/INSTRS b/vm/in/INSTRS index 0f65246..a5fce07 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -138,6 +138,18 @@ decf rm add rm rim addf rm rim +# +# Arithmetical ADD operation, with carry +# +# $1 = $1 + $2 + CF +# +# Sets CF if unsigned integer overflow occur, clears it otherwise +# Sets OF is signed integer overflow occur, clears it otherwise +# Sets ZF and SF according to the result +# +adc rm rim +adcf rm rim + # # Arithmetical SUB operation # @@ -507,6 +519,20 @@ cmc clc stc +#---------------------------------------------------------------------------# +# Byte-wise / bit-wise manipulation instructions # +#---------------------------------------------------------------------------# + +# +# Byte/word/dword swap (xSWAP) +# +# Changes endianness +# +bswap rm rim +wswap rm rim +dswap rm rim + + #---------------------------------------------------------------------------# # Misc. instructions # #---------------------------------------------------------------------------# diff --git a/vm/in/arith.c b/vm/in/arith.c index 05338a6..67b30e8 100644 --- a/vm/in/arith.c +++ b/vm/in/arith.c @@ -93,6 +93,30 @@ IMPL_START_2(addf) } IMPL_OUT_ZSF; +IMPL_START_2(adc) +{ + v1 += v2 + !!(flg&CF); +} +IMPL_OUT; + +IMPL_START_2(adcf) +{ + if (v1 + v2 + !!(flg&CF) < v1) flg |= OF; + else flg &= ~OF; + + v1 += !!(flg&CF); + + if ( ((v2 > 0) && (v1 > LONG_MAX - v2)) + || ((v2 < 0) && (v1 < LONG_MIN - v2)) ) + flg |= CF; + else flg &= ~CF; + + v1 += v2; +} +IMPL_OUT_ZSF; + +//-------------------------------------------------------------------------- + IMPL_START_2(sub) { v1 -= v2; diff --git a/vm/in/misc.c b/vm/in/misc.c new file mode 100644 index 0000000..f4dc08f --- /dev/null +++ b/vm/in/misc.c @@ -0,0 +1,27 @@ +// The OS/K Team licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +IMPL_START_2(bswap) +{ + v1 = ((v2 & 0xFF00000000000000) >> 56) + | ((v2 & 0x00FF000000000000) >> 40) + | ((v2 & 0x0000FF0000000000) >> 24) + | ((v2 & 0x000000FF00000000) >> 8) + | ((v2 & 0x00000000FF000000) << 8) + | ((v2 & 0x0000000000FF0000) << 24) + | ((v2 & 0x000000000000FF00) << 40) + | ((v2 & 0x00000000000000FF) << 56); +} +IMPL_OUT; + +IMPL_START_2(wswap) +{ +} +IMPL_OUT; + +IMPL_START_2(dswap) +{ +} +IMPL_OUT;