这是温冬婵、沈美明老师写的IBM PC汇编语言程序设计中的一道例题,程序的目的是实现对从键盘输入的30个人名按照其对应的ASCII进行升序排列,源码如下:
;NAME_SORT--EX6_11
;**************************************************
.model small
.stack 40h
;**************************************************
.data ;define data segment
namepar label byte ;name parameter list:
maxnlen db 21 ;max. length
namelen db ? ;no. chars entered
namefld db 21 dup(?) ;name
crlf db 13,10,'$'
endaddr dw ?
messg1 db 'Name?','$'
messg2 db 'Sorted names:',13,10,'$'
namectr db 0
nametab db 30 dup(20 dup(' ')) ;name table
namesav db 20 dup(?),13,10,'$'
swapped db 0
;**************************************************
.code ;define code segment
;--------------------------------------------------
begin proc far ;main part of program
;set DS and ES register to current data segment
mov ax,@data ;data segment addr
mov ds,ax ;into DS register
mov es,ax ;and ES register
;MAIN PART OF PROGRAM GOES HERE
cld
lea di,nametab
a20loop:
call b10read ;accept name
cmp namelen,0 ;any more names?
jz a30 ;no,go to sort
cmp namectr,30 ;30 names entered?
je a30 ;yes,go to sort
call d10stor ;store entered name in table
jmp a20loop ;end of input
a30:
cmp namectr,1 ;one or no name entered?
jbe a40 ;yes,exit
call g10sort ;sort stored names
call k10disp ;display sorted names
a40:
mov ax,4c00h ;terminate
int 21h
begin endp ;end of main part of program
;--------------------------------------------------
; Accept name as input:
b10read proc near
mov ah,09
lea dx,messg1 ;display prompt
int 21h
mov ah,0ah
lea dx,namepar ;accept name
int 21h
mov ah,09
lea dx,crlf ;return/linefeed
int 21h
;
mov bh,0 ;clear chars after name
mov bl,namelen ;get count of chars
mov cx,21
sub cx,bx ;calc remaining length
b20:
mov namefld[bx],20h ;set to blank
inc bx
loop b20
ret
b10read endp
;--------------------------------------------------
; Store name in table:
d10stor proc near
inc namectr ;add to number of name
cld
lea si,namefld