iczelion tut35[11]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

	mov ecx,nsize			
searchloop:
	or ecx,ecx
	jz finished
	cmp byte ptr [edi]," "
	je endofword
	cmp byte ptr [edi],9 	; tab
	je endofword

scan the whole word list in the buffer, looking for the white spaces. if a white space is found, we have to determine whether it marks the end or the beginning of a word.

	mov inprogress,true
	mov al,byte ptr [edi]
	mov byte ptr [esi],al
	inc esi
skipit:
	inc edi
	dec ecx
	jmp searchloop

if the byte under scrutiny is not a white space, we copy it to the buffer to construct a word and then continue the scan.

endofword:
	cmp inprogress,true
	je wordfound
	jmp skipit

if a white space is found, we check the value in inprogress. if the value is true, we can assume that the white space marks the end of a word and we may proceed to put the word currently in the local buffer (pointed to by esi) into a wordinfo structure. if the value is false, we continue the scan until a non-white space character is found.

wordfound:
	mov byte ptr [esi],0
	push ecx
	invoke heapalloc,hheap,heap_zero_memory,sizeof wordinfo

when the end of a word is found, we append 0 to the buffer to make the word an asciiz string. we then allocate a block of memory from the heap the size of wordinfo for this word.

	push esi
	mov esi,eax
	assume esi:ptr wordinfo
	invoke lstrlen,addr buffer
	mov [esi].wordlen,eax

we obtain the length of the word in the local buffer and store it in the wordlen member of the wordinfo structure, to be used as a quick comparison.

	push arrayoffset
	pop [esi].pcolor

store the address of the dword that contains the color to be used to hilight the word in pcolor member.

	inc eax
	invoke heapalloc,hheap,heap_zero_memory,eax
	mov [esi].pszword,eax
	mov edx,eax
	invoke lstrcpy,edx,addr buffer

allocate memory from the heap to store the word itself. right now, the wordinfo structure is ready to be inserted into the appropriate linked list.

	mov eax,parray
	movzx edx,byte ptr [buffer]
	shl edx,2		; multiply by 4
	add eax,edx

parray contains the address of asmsyntaxarray. we want to move to the dword that has the same index as the value of the first character of the word. so we put the first character of the word in edx then multiply edx by 4 (because each element in asmsyntaxarray is 4 bytes in size) and then add the offset to the address of asmsyntaxarray. we have the address of the corresponding dword in eax.

	.if dword ptr [eax]==0
		mov dword ptr [eax],esi
	.else
		push dword ptr [eax]
		pop [esi].nextlink
		mov dword ptr [eax],esi
	.endif

check the value of the dword. if it's 0, it means there is currently no word that begins with this character in the list. we thus put the address of the current wordinfo structure in that dword.

if the value in the dword is not 0, it means there is at least one word that begins with this character in the array. we thus insert this wordinfo structure to the head of the linked list and update its nextlink member to point to the next wordinfo structure.

	pop esi
	pop ecx
	lea esi,buffer
	mov inprogress,false
	jmp skipit

after the operation is complete, we begin the next scan cycle until the end of buffer is reached.

本文关键:iczelion asm
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top