汇编语言实现排序 20
展开全部
以下是输入20个以下的字符,用冒泡法按从小到大排列输出的程序,希望对你用所帮助:
data segment
da1 db 20,?,20 dup (0)
data ends
stack segment stack
dw 20 dup (0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
lea dx,da1
mov ah,0ah
int 21h
lea bx,da1+1
mov cl,[bx] ;保存字符个数
inc bx ;ds:bx指向第一个字符
mov ch,1
goon1:
cmp ch,cl
jnb over1
mov dl,1
mov si,0
goon2:
mov al,cl
sub al,ch
cmp dl,al
ja over2
mov al,[bx+si]
cmp al,[bx+si+1]
jna over3
mov al,[bx+si]
xchg al,[bx+si+1]
mov [bx+si],al
over3:
inc dl
inc si
jmp goon2
over2:
inc ch
jmp goon1
over1:
mov dx,bx
mov ch,0
add bx,cx
mov al,'$'
mov [bx],al ;把结束标志变为$
mov ah,9
int 21h
mov ax,4c00h
int 21h
code ends
end start
data segment
da1 db 20,?,20 dup (0)
data ends
stack segment stack
dw 20 dup (0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
lea dx,da1
mov ah,0ah
int 21h
lea bx,da1+1
mov cl,[bx] ;保存字符个数
inc bx ;ds:bx指向第一个字符
mov ch,1
goon1:
cmp ch,cl
jnb over1
mov dl,1
mov si,0
goon2:
mov al,cl
sub al,ch
cmp dl,al
ja over2
mov al,[bx+si]
cmp al,[bx+si+1]
jna over3
mov al,[bx+si]
xchg al,[bx+si+1]
mov [bx+si],al
over3:
inc dl
inc si
jmp goon2
over2:
inc ch
jmp goon1
over1:
mov dx,bx
mov ch,0
add bx,cx
mov al,'$'
mov [bx],al ;把结束标志变为$
mov ah,9
int 21h
mov ax,4c00h
int 21h
code ends
end start
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询