I am trying to write code that compares 2 strings. Let's assume that string1 is referred to by SI and string2 is referred to by DI and that each string length is 50.

Is this correct?

Mov SI,2000H
Mov DI,3000H
Mov CX,50H
CLD
REPNE CMPSW
有帮助吗?

解决方案

Some problems:

  • 50H is 80 decimal
  • you're - by using the CMPSW instruction - effectively comparing words (16 bit), ie 160 bytes
  • I think you want to use the REPE prefix, which repeats the instruction as long as the compared elements are equal. Or until the number of comparisons in CX was performed of course.

Re what to put in CX: well, if you're certain your string will always have length that's a multiple of 2 CMPSW is faster. You just have to adjust the contents of CX

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top