我認爲這是檢查溢出的計算未知目的。
sub ecx,edi ; ecx = ??? no idea where these come from or what they mean
sar edx,1 ; edx changed but value is lost, as are flags, no idea why this is done
mov eax,2AAAAAABh ; eax = 715827883, no idea why this number is important
imul ecx ; edx:eax = (original ecx-edi) * 715827883
mov eax,edx ; eax = high-dword of product
shr eax,31 ; eax = high-bit of high-dword of product
add eax,edx ; eax = high-dword of product + high-bit of high-dword of product
; assuming 0 <= ecx < ~10, eax will be zero if the result did not carry into edx
; assuming ~-10 < ecx < 0, eax will be zero if the result did not carry into edx
; therefore, |ecx|<~10, eax = overflow-from-multiplication
test eax,eax
jle ... ; taken if eax=0 or SF=OF
我不確定「sign flag = overflow flag」部分的意義是什麼意思。對於小的ecx值可能不會發生。
'ecx','edx','edi'和'eax'是[寄存器(HTTPS: //en.wikipedia.org/wiki/X86_assembly_language)。 'test'指令設置'jle'這樣的條件指令使用的'cflags'。 – Jason 2014-10-09 05:54:49
我的意思是,'ecx','edx'和'edi'寄存器包含這個代碼塊的輸入值。 – 2014-10-09 05:56:01
'ecx'通常是一個循環計數寄存器,'edi'是一個目標寄存器,所以它可能在一個數組上循環。您需要確定每個寄存器的用途,以確定代碼實際上在做什麼。 – Jason 2014-10-09 06:09:15