【发布时间】:2014-05-03 04:16:00
【问题描述】:
Str_compare PROC USES eax edx esi edi,
string1: PTR BYTE,
string2: PTR BYTE
;
; Compare two strings.
; Returns nothing, but the Zero and Carry flags are affected
; exactly as they would be by the CMP instruction.
;-----------------------------------------------------------
mov esi, string1
mov edi, string2
L1: mov al, [esi]
mov dl, [edi]
cmp al, 0
jne L2
cmp dl, 0
jne L2
jmp L3
L2: inc esi
inc edi
cmp al, dl
je L1
L3: ret
Str_compare ENDP
针对上面的代码,如果string1 只是byte 0 而string2 是一些长度不为0 的常见字符串呢?
我想,当cpu第一次进入L1时,IP会在cmp dl, 0之后跳转到L2。 inc esi 会让 esi 指向 string1 的 0 字节之后的内容未知字节,所以这个程序会崩溃,对吧?
【问题讨论】:
-
esi可以有任何你想要的值,只要你不尝试访问它...... Irvine 博士的代码没有...... -
@FrankKotler
Dr. Irvine's code does not...是什么意思? -
mov al, [esi]在esi指向“坏地方”后不做。迈克尔说的。学习使用调试器或学习像 CPU 一样思考。后者可能更容易。 :)