http://vcbin.blogchina.com/3742015.html
【汇编语言】电话号码查询程序
;实现电话号码插入和查询
data_seg segment
namcount dw 0 ;存入名字的个数
tel_tab db 50 dup(28 dup(' ')) ;表格
nameitem label byte
nmax db 21
ncurlen db ?
namefld db 21 dup(?) ;姓名缓冲区
phoneitem label byte
pmax db 9
pcurlen db ?
phonefld db 9 dup(?) ;电话号码缓冲区
addend dw ? ;排序时的tel_tab尾地址指针
namtemp db 28 dup(?),13,10,'$' ;临时保存表中一项
swap db 0 ;排序中是否有交换的标志位
msg_count db 'Please enter the count you want to input?',13,10,'$'
msg_illcount db 'Error:The number of your enter exceed the limit of 50! Plesae input the number again!',13,10,'$'
msg_illch db 'Error:The number of your enter is illegal! Please intput the number again!',13,10,'$'
msg_inputnam db 'Input name:','$'
msg_inputerr db 'Error:Input error!,please input a name!',13,10,'$'
msg_inputnum db 'Input a telephone number:','$'
msg_inquire db 'Do you want a telephone number?(Y/N)','$'
msg_sname db 'name?',13,10,'$'
msg_outtitle db 'name tel.',13,10,'$'
msg_nomatch db 'No such name!Do you want to insert this item(Y/N)?',13,10,'$'
msg_result db 'The Phone Dictionary is listed as follows:',13,10,'$'
data_seg ends
stack_seg segment para stack 'stack' ;定义堆栈段
dw 256 dup(0)
stack_seg ends
code_seg segment
assume cs:code_seg,ds:data_seg,es:data_seg,ss:stack_seg
main proc far
start:
mov ax,data_seg
mov ds,ax ;初始化数据段
mov es,ax ;初始化附加段
cld ;df=0
lea di,tel_tab ;名字表的首地址放入di
lea dx,msg_count
mov ah,9
int 21h ;显示信息0:'How many names do you want to enter?'
again:call decibin ;调用decibin(将输入的十进制次数转换成机器能识别的二进制数)
cmp dx,2 ;注意该条语句和下面的跳转语句的位置.计数器(记录名字数的位数)
call crlf;回车换行
je exit1 ;一个有效字符都没输入,跳转要求重新输入.输入的为非法字符即非数字则不等输入完就跳出
push bx
cmp bx,50 ;
ja return ;输入的个数大于50出错跳出
;输入表中项数并保存在bx中
repeat:pop bx
cmp namcount,bx ;目前项数和要求输入的项数比较,名字数和bx比较
je choice ;如果所有项都输入完毕则跳到choice排序
push bx ;stor_name会用到bx,先保存
lea dx,msg_inputnam
mov ah,9
int 21h ;要求输入名字
call input_name ;调用input_name
cmp ncurlen,0 ;没有输入了则开始排序,输入名字的字符数为0跳转
je choice
call stor_name
call input_phone ;调用input_phone
jmp repeat ;由于tel_tab是顺序连续存储,每一次输入一项后,di即指向下一项的开始,所以无需调整
choice:cmp namcount,1
jb return1 ;表中项数小于1则要求输入
call name_sort ;不小于调用name_sort
【汇编语言】电话号码查询程序
;实现电话号码插入和查询
data_seg segment
namcount dw 0 ;存入名字的个数
tel_tab db 50 dup(28 dup(' ')) ;表格
nameitem label byte
nmax db 21
ncurlen db ?
namefld db 21 dup(?) ;姓名缓冲区
phoneitem label byte
pmax db 9
pcurlen db ?
phonefld db 9 dup(?) ;电话号码缓冲区
addend dw ? ;排序时的tel_tab尾地址指针
namtemp db 28 dup(?),13,10,'$' ;临时保存表中一项
swap db 0 ;排序中是否有交换的标志位
msg_count db 'Please enter the count you want to input?',13,10,'$'
msg_illcount db 'Error:The number of your enter exceed the limit of 50! Plesae input the number again!',13,10,'$'
msg_illch db 'Error:The number of your enter is illegal! Please intput the number again!',13,10,'$'
msg_inputnam db 'Input name:','$'
msg_inputerr db 'Error:Input error!,please input a name!',13,10,'$'
msg_inputnum db 'Input a telephone number:','$'
msg_inquire db 'Do you want a telephone number?(Y/N)','$'
msg_sname db 'name?',13,10,'$'
msg_outtitle db 'name tel.',13,10,'$'
msg_nomatch db 'No such name!Do you want to insert this item(Y/N)?',13,10,'$'
msg_result db 'The Phone Dictionary is listed as follows:',13,10,'$'
data_seg ends
stack_seg segment para stack 'stack' ;定义堆栈段
dw 256 dup(0)
stack_seg ends
code_seg segment
assume cs:code_seg,ds:data_seg,es:data_seg,ss:stack_seg
main proc far
start:
mov ax,data_seg
mov ds,ax ;初始化数据段
mov es,ax ;初始化附加段
cld ;df=0
lea di,tel_tab ;名字表的首地址放入di
lea dx,msg_count
mov ah,9
int 21h ;显示信息0:'How many names do you want to enter?'
again:call decibin ;调用decibin(将输入的十进制次数转换成机器能识别的二进制数)
cmp dx,2 ;注意该条语句和下面的跳转语句的位置.计数器(记录名字数的位数)
call crlf;回车换行
je exit1 ;一个有效字符都没输入,跳转要求重新输入.输入的为非法字符即非数字则不等输入完就跳出
push bx
cmp bx,50 ;
ja return ;输入的个数大于50出错跳出
;输入表中项数并保存在bx中
repeat:pop bx
cmp namcount,bx ;目前项数和要求输入的项数比较,名字数和bx比较
je choice ;如果所有项都输入完毕则跳到choice排序
push bx ;stor_name会用到bx,先保存
lea dx,msg_inputnam
mov ah,9
int 21h ;要求输入名字
call input_name ;调用input_name
cmp ncurlen,0 ;没有输入了则开始排序,输入名字的字符数为0跳转
je choice
call stor_name
call input_phone ;调用input_phone
jmp repeat ;由于tel_tab是顺序连续存储,每一次输入一项后,di即指向下一项的开始,所以无需调整
choice:cmp namcount,1
jb return1 ;表中项数小于1则要求输入
call name_sort ;不小于调用name_sort