kvisc/vm/in/string.c

69 lines
2.1 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)
{
DECV(v2, p2);
writemem(ctx, v2, R(p1->reg), len);
STR_MOVE(p1->reg, len);
}
IMPL_START_0(stosb) { stos_impl(ctx, p1, p2, 1); } IMPL_END;
IMPL_START_0(stosw) { stos_impl(ctx, p1, p2, 2); } IMPL_END;
IMPL_START_0(stosl) { stos_impl(ctx, p1, p2, 4); } IMPL_END;
IMPL_START_0(stosq) { stos_impl(ctx, p1, p2, 8); } IMPL_END;
//----------------------------------------------------------------------------//
static void scas_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
DECV(v2, p2);
ulong x = readmem(ctx, R(p1->reg), len);
COMPARE_SUB(x, v2);
if (x == 0) {
R(RFX) |= ZF;
}
else if (!(R(RFX)&ZF)) {
STR_MOVE(p1->reg, len);
}
}
IMPL_START_0(scasb) { scas_impl(ctx, p1, p2, 1); } IMPL_END;
IMPL_START_0(scasw) { scas_impl(ctx, p1, p2, 2); } IMPL_END;
IMPL_START_0(scasl) { scas_impl(ctx, p1, p2, 4); } IMPL_END;
IMPL_START_0(scasq) { scas_impl(ctx, p1, p2, 8); } IMPL_END;
//----------------------------------------------------------------------------//
static void movs_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len)
{
ulong x = readmem(ctx, R(p2->reg), len);
writemem(ctx, x, R(p1->reg), len);
R(RFX) = (x == 0 ? R(RFX)|ZF : R(RFX)&~ZF);
STR_MOVE(p1->reg, len);
STR_MOVE(p2->reg, len);
}
IMPL_START_0(movsb) { movs_impl(ctx, p1, p2, 1); } IMPL_END;
IMPL_START_0(movsw) { movs_impl(ctx, p1, p2, 2); } IMPL_END;
IMPL_START_0(movsl) { movs_impl(ctx, p1, p2, 4); } IMPL_END;
IMPL_START_0(movsq) { movs_impl(ctx, p1, p2, 8); } IMPL_END;
//----------------------------------------------------------------------------//