mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
54 lines
1.6 KiB
C
54 lines
1.6 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(acc_t *p1, acc_t *p2, uint len)
|
|
{
|
|
if (p1->type != A_REG)
|
|
_except(E_ILL, "STOSX given a non-REG operand");
|
|
|
|
writemem(p2->val, R(p1->reg), len);
|
|
STR_MOVE(p1->reg, len);
|
|
}
|
|
|
|
IMPL_START(stosb) { stos_impl(p1, p2, 1); return 0; }
|
|
IMPL_START(stosw) { stos_impl(p1, p2, 2); return 0; }
|
|
IMPL_START(stosd) { stos_impl(p1, p2, 4); return 0; }
|
|
IMPL_START(stosq) { stos_impl(p1, p2, 8); return 0; }
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
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");
|
|
|
|
ulong x = readmemsx(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(p1, p2, 1); return 0; }
|
|
IMPL_START(scasw) { scas_impl(p1, p2, 2); return 0; }
|
|
IMPL_START(scasd) { scas_impl(p1, p2, 4); return 0; }
|
|
IMPL_START(scasq) { scas_impl(p1, p2, 8); return 0; }
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|