Is this correct assembly?
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
精彩评论