1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/vm/in/string.c
julianb0 89ed8fdc0d
vm
2019-08-03 17:41:44 +02:00

54 lines
1.7 KiB
C

// 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 <in/instrs.h>
//----------------------------------------------------------------------------//
#define STR_MOVE(reg, len) \
if (!(R(RFX) & DF)) R(reg) += len; \
else R(reg) -= len;
//----------------------------------------------------------------------------//
static void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
if (p1->type != A_REG)
_except(ctx, E_ILL, "STOSX given a non-REG operand");
writemem(ctx, p2->val, R(p1->reg), len);
STR_MOVE(p1->reg, len);
}
IMPL_START(stosb) { stos_impl(ctx, p1, p2, 1); return 0; }
IMPL_START(stosw) { stos_impl(ctx, p1, p2, 2); return 0; }
IMPL_START(stosd) { stos_impl(ctx, p1, p2, 4); return 0; }
IMPL_START(stosq) { stos_impl(ctx, p1, p2, 8); return 0; }
//----------------------------------------------------------------------------//
static void scas_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
if (p1->type != A_REG)
_except(ctx, E_ILL, "SCASX given a non-REG operand");
ulong x = readmemsx(ctx, R(p1->reg), len);
COMPARE_SUB(x, p2->val);
if (x == 0) {
R(RFX) |= ZF;
}
else if (!(R(RFX)&ZF)) {
STR_MOVE(p1->reg, len);
}
}
IMPL_START(scasb) { scas_impl(ctx, p1, p2, 1); return 0; }
IMPL_START(scasw) { scas_impl(ctx, p1, p2, 2); return 0; }
IMPL_START(scasd) { scas_impl(ctx, p1, p2, 4); return 0; }
IMPL_START(scasq) { scas_impl(ctx, p1, p2, 8); return 0; }
//----------------------------------------------------------------------------//