用汇编语言实现数据的由小到大排序?? 80
1个回答
展开全部
data segment
num dw 20 dup(?);存输入数列
i dw 0 ;数列个数
max dw ?
min dw ?
char1 db 'The maximum number is:$'
char2 db 0dh,'The minimum number is:$'
char3 db 0dh,'The order of the numbers is:',0ah,0dh,'$'
rec db 5 dup(?) ;输出缓存
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
mov ax,data
mov ds,ax
mov si,0
mov bx,0
input:
mov ah,01h
int 21h
cmp al,20h;遇到空格写数据
jz write1
cmp al,0dh;遇到回车写最后一个数据
jz write2
sub al,30h
mov cl,al
mov ch,00h
mov ax,bx
mov bx,0ah
mul bx
mov bx,ax
add bx,cx
jmp input
write1: ;write the numbers before Space
mov [num+si],bx
add si,2
inc i
mov bx,0
jmp input
write2: ;write the last one number before Enter
mov [num+si],bx
add si,2
inc i
mov dl,0ah
mov ah,02h
int 21h
beforemax:
mov bx,0
mov cx,i
dec cx
mov ax,[num+bx]
maximum:
add bx,2
cmp ax,[num+bx]
jnb nextmax
mov ax,[num+bx]
nextmax:
loop maximum
mov max,ax
beforemin:
mov bx,0
mov cx,i
dec cx
mov ax,[num+bx]
minimum:
add bx,2
cmp ax,[num+bx]
jbe nextmin
mov ax,[num+bx]
nextmin:
loop minimum
mov min,ax
beforeorder:
mov cx,i
dec cx
loop1:
mov di,cx
mov bx,0
loop2:
mov ax,num[bx]
cmp ax,num[bx+2]
jbe continue
xchg ax,num[bx+2]
mov num[bx],ax
continue:
add bx,2
loop loop2
mov cx,di
loop loop1
initmax: ;changemax初始化
lea dx,char1
mov ah,09h
int 21h
mov ax,max
mov bx,10
mov si,4
changemax: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changemax
outputmax: ;输出(从initmax开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputmax
mov dl,0ah
mov ah,02h
int 21h
initmin: ;changemin初始化
lea dx,char2
mov ah,09h
int 21h
mov ax,min
mov bx,10
mov si,4
changemin: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changemin
outputmin: ;输出(从initmin开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputmin
mov dl,0ah
mov ah,02h
int 21h
initnum: ;changenum初始化
lea dx,char3
mov ah,09h
int 21h
mov cx,i
mov di,0
loopnum:
mov ax,[num+di]
add di,2
mov bx,10
mov si,4
changenum: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changenum
outputnum: ;输出(从initnum开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputnum
mov dl,20h
mov ah,02h
int 21h
loop loopnum
stop:
mov ah,4ch
int 21h
main endp
code ends
end start
请注意我的是无符号数的,你稍微改改应该就行了,最近做课程设计,比较忙,所以没空帮你改
另外,我的输入方式是一个数后空格再输入一个数,最后一个数按回车,你如果不习惯也可以改成输入一个数后回车,按其他字符结束
num dw 20 dup(?);存输入数列
i dw 0 ;数列个数
max dw ?
min dw ?
char1 db 'The maximum number is:$'
char2 db 0dh,'The minimum number is:$'
char3 db 0dh,'The order of the numbers is:',0ah,0dh,'$'
rec db 5 dup(?) ;输出缓存
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
mov ax,data
mov ds,ax
mov si,0
mov bx,0
input:
mov ah,01h
int 21h
cmp al,20h;遇到空格写数据
jz write1
cmp al,0dh;遇到回车写最后一个数据
jz write2
sub al,30h
mov cl,al
mov ch,00h
mov ax,bx
mov bx,0ah
mul bx
mov bx,ax
add bx,cx
jmp input
write1: ;write the numbers before Space
mov [num+si],bx
add si,2
inc i
mov bx,0
jmp input
write2: ;write the last one number before Enter
mov [num+si],bx
add si,2
inc i
mov dl,0ah
mov ah,02h
int 21h
beforemax:
mov bx,0
mov cx,i
dec cx
mov ax,[num+bx]
maximum:
add bx,2
cmp ax,[num+bx]
jnb nextmax
mov ax,[num+bx]
nextmax:
loop maximum
mov max,ax
beforemin:
mov bx,0
mov cx,i
dec cx
mov ax,[num+bx]
minimum:
add bx,2
cmp ax,[num+bx]
jbe nextmin
mov ax,[num+bx]
nextmin:
loop minimum
mov min,ax
beforeorder:
mov cx,i
dec cx
loop1:
mov di,cx
mov bx,0
loop2:
mov ax,num[bx]
cmp ax,num[bx+2]
jbe continue
xchg ax,num[bx+2]
mov num[bx],ax
continue:
add bx,2
loop loop2
mov cx,di
loop loop1
initmax: ;changemax初始化
lea dx,char1
mov ah,09h
int 21h
mov ax,max
mov bx,10
mov si,4
changemax: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changemax
outputmax: ;输出(从initmax开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputmax
mov dl,0ah
mov ah,02h
int 21h
initmin: ;changemin初始化
lea dx,char2
mov ah,09h
int 21h
mov ax,min
mov bx,10
mov si,4
changemin: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changemin
outputmin: ;输出(从initmin开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputmin
mov dl,0ah
mov ah,02h
int 21h
initnum: ;changenum初始化
lea dx,char3
mov ah,09h
int 21h
mov cx,i
mov di,0
loopnum:
mov ax,[num+di]
add di,2
mov bx,10
mov si,4
changenum: ;二进制->BCD
mov dx,0
div bx
mov [rec+si],dl
dec si
cmp ax,0
ja changenum
outputnum: ;输出(从initnum开始,做预备工作)
inc si
mov dl,[rec+si]
add dl,30h
mov ah,02h
int 21h
cmp si,4
jb outputnum
mov dl,20h
mov ah,02h
int 21h
loop loopnum
stop:
mov ah,4ch
int 21h
main endp
code ends
end start
请注意我的是无符号数的,你稍微改改应该就行了,最近做课程设计,比较忙,所以没空帮你改
另外,我的输入方式是一个数后空格再输入一个数,最后一个数按回车,你如果不习惯也可以改成输入一个数后回车,按其他字符结束
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询