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 cbd079d2a0
vm
2019-08-14 20:23:05 +02:00

39 lines
1.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 scas_impl(acc_t *p1, acc_t *p2, uint len)
{
if (p1->type != A_REG)
_except(E_ILL, "SCASX given a non-REG operand");
while (R(RCX) > 0)
{
ulong x = readmemzx(R(p1->reg), len);
if (x == 0 || x == p2->val)
break;
R(p1->reg) += len;
R(RCX)--;
}
}
IMPL_START(scasb, 2) { scas_impl(p1, p2, 1); return 0; }
IMPL_START(scasw, 2) { scas_impl(p1, p2, 2); return 0; }
IMPL_START(scasd, 2) { scas_impl(p1, p2, 4); return 0; }
IMPL_START(scasq, 2) { scas_impl(p1, p2, 8); return 0; }
//----------------------------------------------------------------------------//