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

54 lines
1.6 KiB
C
Raw Normal View History

2019-06-13 15:32:24 +02:00
// 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>
//----------------------------------------------------------------------------//
2019-06-13 16:27:33 +02:00
#define STR_MOVE(reg, len) \
2019-07-17 22:25:50 +02:00
if (!(R(RFX) & DF)) R(reg) += len; \
2019-07-17 20:26:03 +02:00
else R(reg) -= len;
2019-06-13 16:27:33 +02:00
//----------------------------------------------------------------------------//
2019-08-03 19:01:12 +02:00
static void stos_impl(acc_t *p1, acc_t *p2, uint len)
2019-06-13 16:27:33 +02:00
{
2019-08-03 17:41:44 +02:00
if (p1->type != A_REG)
2019-08-03 19:01:12 +02:00
_except(E_ILL, "STOSX given a non-REG operand");
2019-08-03 17:41:44 +02:00
2019-08-03 19:01:12 +02:00
writemem(p2->val, R(p1->reg), len);
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
2019-06-13 16:27:33 +02:00
}
2019-08-08 18:39:12 +02:00
IMPL_START(stosb, 2) { stos_impl(p1, p2, 1); return 0; }
IMPL_START(stosw, 2) { stos_impl(p1, p2, 2); return 0; }
IMPL_START(stosd, 2) { stos_impl(p1, p2, 4); return 0; }
IMPL_START(stosq, 2) { stos_impl(p1, p2, 8); return 0; }
2019-06-13 17:13:59 +02:00
2019-06-13 15:47:20 +02:00
//----------------------------------------------------------------------------//
2019-08-03 19:01:12 +02:00
static void scas_impl(acc_t *p1, acc_t *p2, uint len)
2019-06-13 22:20:35 +02:00
{
2019-08-03 17:41:44 +02:00
if (p1->type != A_REG)
2019-08-03 19:01:12 +02:00
_except(E_ILL, "SCASX given a non-REG operand");
2019-08-03 17:41:44 +02:00
2019-08-03 19:01:12 +02:00
ulong x = readmemsx(R(p1->reg), len);
2019-07-24 16:52:26 +02:00
COMPARE_SUB(x, p2->val);
2019-06-13 22:20:35 +02:00
2019-06-17 20:59:30 +02:00
if (x == 0) {
2019-07-11 18:34:21 +02:00
R(RFX) |= ZF;
2019-06-13 22:20:35 +02:00
}
2019-07-11 18:34:21 +02:00
else if (!(R(RFX)&ZF)) {
2019-06-17 20:59:30 +02:00
STR_MOVE(p1->reg, len);
2019-06-13 22:20:35 +02:00
}
}
2019-08-08 18:39:12 +02:00
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; }
2019-06-13 15:32:24 +02:00
//----------------------------------------------------------------------------//