Confusingly with CMPSB instruction

I was looking at this code and I am confused about the cmpsb rep 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

I understand that it repeats cmpsb cx times, but how does it compare two lines? Say, for example, there was a comparison of "Hey \ 0" and "hey \ 0", and this loop compared 4 lines of characters. The first characters are different, and the EFlags case will be set accordingly. However, the cmpsb command repeats and the following characters are the same. I may not understand how cmpsb works , but it looks like this loop is incorrectly matching two lines. Does this loop really work?

+5
source share
4 answers

REP , rep , REPE (F3h). , REPE - , , REP .

, cmpsb REPE, , () .

+10

, REPE REPNE cmpsb ( ).

+1

, . repe cmpsb ( ).

+1

, brokenthorn, Imagename , .

It will continue until all 11 characters (file name and extension) disappear from the first difference. It will set the ZF flag if they are the same and the ZF flag will be cleared.

So, after comparing the entire file name, it will go on to download this bold record if they are the same. If not, it will load the next entry and compare that file name.

0
source

All Articles