Signed-off-by: Mohamed Mediouni <[email protected]>
---
target/i386/emulate/x86_emu.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/target/i386/emulate/x86_emu.c b/target/i386/emulate/x86_emu.c
index 4409f7bc13..bf96fe06b4 100644
--- a/target/i386/emulate/x86_emu.c
+++ b/target/i386/emulate/x86_emu.c
@@ -466,18 +466,25 @@ static inline void string_increment_reg(CPUX86State *env,
int reg,
write_reg(env, reg, val, decode->addressing_size);
}
+static inline int get_ZF(CPUX86State *env) {
+ return env->cc_dst ? 0 : CC_Z;
+}
+
static inline void string_rep(CPUX86State *env, struct x86_decode *decode,
void (*func)(CPUX86State *env,
struct x86_decode *ins), int rep)
{
target_ulong rcx = read_reg(env, R_ECX, decode->addressing_size);
- while (rcx--) {
+
+ while (rcx != 0) {
+ bool is_cmps_or_scas = decode->cmd == X86_DECODE_CMD_CMPS ||
decode->cmd == X86_DECODE_CMD_SCAS;
func(env, decode);
+ rcx--;
write_reg(env, R_ECX, rcx, decode->addressing_size);
- if ((PREFIX_REP == rep) && !env->cc_dst) {
+ if ((PREFIX_REP == rep) && !get_ZF(env) && is_cmps_or_scas) {
break;
}
- if ((PREFIX_REPN == rep) && env->cc_dst) {
+ if ((PREFIX_REPN == rep) && get_ZF(env)&& is_cmps_or_scas) {
break;
}
}
--
2.50.1 (Apple Git-155)