logo资料库

将一个数组的所有元素排序后输出.doc

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
;Program:将数组中的 10 个数按从小到大排序并输出 ;Author: ;Date:11/2009 .386 .MODEL FLAT ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD INCLUDE io.h ; header file for input/output cr Lf EQU EQU 0dh 0ah ; carriage return character ; line feed .STACK 4096 ; reserve 4096-byte stack .DATA prompt1 prompt2 prompt3 array value ; reserve storage for data cr, Lf, "Please input 10 numbers: ",cr,Lf,0 "number: ",0 "The result is :",cr, Lf, 0 BYTE BYTE BYTE DWORD 11 DUP(?) BYTE 11 DUP(?) " BYTE ",0 string BYTE 11 DUP(?) .CODE Sort PROC NEAR32 ; start of main program code ecx,10 ecx edi,ecx ebx,array eax,[ebx] ;从第一个数开始,前后两个数比较 eax,[ebx+4] ;若前后不是<关系,则交换前后两个 ;取数组首地址 ;地址的值,如此循环直到第十个数 mov dec loop1:mov lea loop2:mov cmp jle xchg eax,[ebx+4] [ebx],eax mov continue continue: ebx,4 add loop loop2 mov loop loop1 ret ecx,edi ENDP Sort _start: ;控制大循环(loop1)9 次 mov lea ecx,1 edi, array ;取首地址
StingIn: output mov output input atod mov add loop call mov lea output ;循环 StingIn 十次 prompt1 ecx,10 prompt2 string,11 ;输入数字 string [edi], eax ;存入数组中 edi,4 StingIn Sort ecx,10 esi, array prompt3 ;调用排序子程序 ;循环 OutValue 十次 OutValue: dtoa value, [esi] output add loop value+8 esi,4 OutValue ;依次输出数组中的数 INVOKE ExitProcess, 0 PUBLIC _start END ; exit with return code 0 ; make entry point public ; end of source code
分享到:
收藏