- 9
- 0
- 约3.93千字
- 约 15页
- 2018-03-08 发布于河南
- 举报
7例14-16
例14 从键盘输入20个字符,使用起泡排序对其按降序排序,结果从显示器输出。该程序中子程序和主程序位于同一个段中。
data segment
buff db 20 dup(?)
in_pr db Input 20 characters which will be sorted:$
out_pr db sort have been complished, result is:$
data ends
program segment
assume cs:program,ds:data
cr_lf proc NEAR
mov ah,02h
mov dl,0dh
int 21h
mov ah,02h
mov dl,0ah
int 21h
ret
cr_lf endp
START: mov ax,data
mov ds,ax
mov dx,offset in_pr
mov ah,09
int 21h
call cr_lf
mov cx,20
mov bx,offset buff
cycle0: mov ah,01
int 21h
mov [bx],al
inc bx
mov ah,02h
mov dl,2dh
int 21h
loop cycle0
mov cx,19
cycle1: mov di,cx
mov bx,offset buff
cycle2: mov al,[bx]
cmp al,[bx+1]
jge continu
xchg al,[bx+1]
mov [bx],al
continu:inc bx
loop cycle2
mov cx,di
loop cycle1
call cr_lf
mov ah,09h
mov dx,offset out_pr
int 21h
call cr_lf
mov cx,20
mov bx,offset buff
cycle3: mov ah,02h
mov dl,[bx]
int 21h
inc bx
mov ah,02h
mov dl,2dh
int 21h
loop cycle3
mov ax,4c00h
int 21h
program ends
end START
例15 从键盘输入20个字符,使用起泡排序对其按降序排序,结果从显示器输出。该程序中子程序和主程序位于不同段中。
data segment
buff db 20 dup(?)
in_pr db Input 20 characters which will be sorted:$
out_pr db Sort have been complished, result is:$
data ends
prog2 segment
assume cs:prog2
cr_lf proc FAR
mov ah,02h
mov dl,0dh
int 21h
mov ah,02h
mov dl,0ah
int 21h
ret
cr_lf endp
prog2 ends
prog1 segment
assume cs:prog1,ds:data
main PROC FAR
start: mov ax,data
mov ds,ax
mov dx,offset in_pr
mov ah,09
int 21h
call cr_lf
原创力文档

文档评论(0)