首先对10个数按从小到大排序,然后第一个元素就是最小的,最后一个元素就是最大的 data segment mes1 db 'the max:$' mes2 db 'the min:$' a dw 42,20,100,456,99,120,89,12334,90,1239 data ends code segment main proc far assume cs:code,ds:data start: push ds sub ax,ax push ax mov ax,data mov ds,ax ;以下是起泡排序核心代码 mov cx,10 dec cx loop1: mov di,cx mov bx,0 loop2: mov ax,a[bx] cmp a[bx+2],ax jge cotinue xchg ax,a[bx+2] mov a[bx],ax cotinue: add bx,2 loop loop2 mov cx,di loop loop1 mov dx,offset mes1 mov ah,09h int 21h call crlf mov bx,a[18] call bini ;转换为十进制的子程序 call crlf ;回车换行子程序 mov dx,offset mes2 mov ah,09h int 21h call crlf mov bx,a[0] call bini ret main endp bini proc near mov cx,10000d call bin mov cx,1000d call bin mov cx,100d call bin mov cx,10d call bin mov cx,1d call bin ret bini endp bin proc near mov ax,bx mov dx,0 div cx mov bx,dx mov dl,al add dl,30h mov ah,02h int 21h ret bin endp crlf proc near mov dl,0ah mov ah,02h int 21h mov dl,0dh mov ah,02h int 21 ret crlf endp code ends end start
用汇编语言求一组数的最大值和最小值
最新推荐文章于 2023-11-26 21:33:56 发布