与CMPSB指令混淆 [英] Confused with CMPSB instruction

查看:550
本文介绍了与CMPSB指令混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这个code和我很困惑在代表CMPSB 行。

I have been looking at this code and I'm confused about the rep cmpsb line.

.LOOP:
      push    cx
      mov     cx, 0x000B                            ; eleven character name
      mov     si, ImageName                         ; image name to find
      push    di
 rep  cmpsb                                         ; test for entry match
      pop     di
      je      LOAD_FAT
      pop     cx
      add     di, 0x0020                            ; queue next directory entry
      loop    .LOOP
      jmp     FAILURE

据我所知,它重复CMPSB CX倍,但它如何比较两个字符串?例如说是比较嘿\\ 0和哎\\ 0,这是环比较4字符串。第一个字符是不同的,EFLAGS寄存器会进行相应的设置。然而,在 CMPSB 指令重复,下一个字符将是相同的。我可能是误解了如何 CMPSB 的作品,但它看起来像这样循环不正确地比较两个字符串。难道这个循环其实工作吗?

I understand that it repeats cmpsb cx times but how does this compare the two strings? Say for example was comparing "Hey\0" and "hey\0" and this loop was comparing 4 character strings. The first characters are different and the EFlags register would be set accordingly. However, the cmpsb instruction is repeated and the next characters would be the same. I may be misunderstanding how cmpsb works but it looks like this loop does not correctly compare two strings. Does this loop in fact work?

推荐答案

原因REP的工作原理是,因为代表有同样的编码作为REPE(F3H)。原则上REPE是在这里使用了正确的事情,但是这取决于你的汇编它可能只是需要REP是正确的。

The reason REP works is because rep has the same encoding as REPE (F3h). In principle REPE is the right thing to use here, but depending on your assembler it might just take REP as correct.

因此​​,在现实中,你有一个REPE CMPSB那里,它只是你的(DIS)汇编并不知道。

So in reality you have a REPE cmpsb there, it's just that your (dis)assembler doesn't really know.

这篇关于与CMPSB指令混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆