diff --git a/bdshemu/bdshemu_x86.c b/bdshemu/bdshemu_x86.c index c174c12..cb56c80 100644 --- a/bdshemu/bdshemu_x86.c +++ b/bdshemu/bdshemu_x86.c @@ -2640,8 +2640,9 @@ ShemuX86Emulate( case ND_INS_LODS: case ND_INS_STOS: case ND_INS_MOVS: - // Fetch the rCX register, which is the third operand in case of repeated instructions. - while (Context->InstructionsCount < Context->MaxInstructionsCount) + // do/while: outer loop already gated this dispatch on a budget slot, + // so iteration #1 must run even at MaxInstructionsCount == 1. + do { // Get the RCX value. GET_OP(Context, 2, &dst); @@ -2667,12 +2668,13 @@ ShemuX86Emulate( } Context->InstructionsCount++; - } + } while (Context->InstructionsCount < Context->MaxInstructionsCount); break; case ND_INS_SCAS: case ND_INS_CMPS: - while (Context->InstructionsCount < Context->MaxInstructionsCount) + // Same budget contract as MOVS above. + do { // Get the RCX value. GET_OP(Context, 2, &dst); @@ -2717,7 +2719,7 @@ ShemuX86Emulate( } Context->InstructionsCount++; - } + } while (Context->InstructionsCount < Context->MaxInstructionsCount); break; case ND_INS_MUL: