X86汇编语言(四)

来源:互联网 发布:mac做app开发 编辑:程序博客网 时间:2024/05/21 08:37

快速排序的非递归实现

include Irvine32.incarraySize = 250000.dataarray DWORD arraySize dup(?)pivot DWORD ?starttime dword ?.codemain PROCcall Randomizemov ecx,arraySizemov esi,0mov eax,arraySizeL1:call Random32mov array[esi*type array],eaxinc esiloop L1call GetMsecondsmov starttime,eaxmov eax,0mov ebx,arraySize -1call quickSortcall GetMsecondssub eax,starttimecall WriteIntcall Crlfexitmain endpPartition procpushadmov edx,array[eax*type array]L1:cmp eax,ebxjae stopL2:cmp eax,ebxjae L3cmp array[ebx*type array],edxjl L3dec ebxjmp L2L3:mov ecx,array[ebx*type array]mov array[eax*type array],ecxL4:cmp eax,ebxjae L5cmp array[eax*type array],edxjg L5inc eaxjmp L4L5:mov ecx,array[eax*type array]mov array[ebx*type array],ecxjmp L1stop:mov array[eax*type array],edxmov pivot,eaxpopadretPartition endpquickSort procpushad.datatemp DWORD 0.codemov temp,esppush eaxpush ebxL1:cmp esp,tempje stoppop ebxpop eaxcall Partitiondec pivotcmp eax,pivotjge L2push eaxpush pivotL2:add pivot,2cmp ebx,pivotjle L3push pivotpush ebxL3:jmp L1stop:popadretquickSort endpEND main
使用汇编语言实现的非递归的快速排序程序,其中,使用eax与ebx传递待排数组下标范围。
原创粉丝点击