⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2-4.asm

📁 几个汇编小程序。能实现电话号码本的管理
💻 ASM
字号:
dataseg segment
  maxnlen db 21
  namelen db ?
  namefld db 21 dup(?)
  telepho db 9
  telelen db ?
  telep db 9 dup(?)
  teletab db 50 dup(28 dup(?))
  totle dw 0
  endtel dw ?
  swapped dw ?
  temp dw ?
  telephsort db 28 dup(?),13,10,'$'
  message1 db 0ah,0dh,'Input name:','$'
  message2 db 'Input telephone:','$'
  message3 db 0ah,0dh,'The wrong telephone number,Input again!',0ah,0dh,'$'
  message4 db 0ah,0dh,'Finish?(Y/N):','$'
  message5 db 0ah,0dh,'Research?(Y/N):','$'
  message6 db 0ah,0dh,'Input search name:','$'
  message7 db 0ah,0dh,'NAME                TELEPHONE',0ah,0dh,'$'
  message8 db 0ah,0dh,'Not find',0ah,0dh,'$'
  crlt db 0ah,0dh,'$'
dataseg ends

;----------------------------main program-----------------------------------

code segment
main proc far
  assume cs:code,ds:dataseg,es:dataseg
start:
  push ds
  sub ax,ax
  push ax
  mov ax,dataseg
  mov ds,ax
  mov es,ax
  lea di,teletab
inname:
  call putname
  call puttele
  cmp totle,50
  ja next1
  lea dx,message4
  mov ah,09h
  int 21h
  mov ah,01h
  int 21h
  cmp al,79h
  jnz inname
next1:
  call sort1
next2:
  lea dx,message5
  mov ah,09h
  int 21h
nextt:
  mov ah,01h
  int 21h
  cmp al,79h
  jz yess
  cmp al,59h
  jz yess
  cmp al,6eh
  jz exit
  cmp al,4eh
  jz exit
  jmp nextt
yess:
  call research
  jmp next2
exit:
  ret
main endp

;-----------------------------input the name -----------------------------------------

putname proc near
  inc totle
  mov dx,offset message1
  mov ah,9h
  int 21h
  mov dx,offset maxnlen
  mov ah,0ah
  int 21h
  lea dx,crlt
  mov ah,09h
  int 21h
  mov bh,0
  mov bl,namelen
  mov cx,21
  sub cx,bx
b20:
  mov namefld[bx],20h
  inc bx
  loop b20
  cld
  lea si,namefld
  mov cx,20
  rep movsb
  ret
putname endp
;-----------------------------input the telephone ------------------------------------------
puttele proc near
next:
  lea dx,message2
  mov ah,09h
  int 21h
  mov dx,offset telepho
  mov ah,0ah
  int 21h
  cmp telelen,8
  jnz error1
  cld
  lea si,telep
  mov cx,8
  rep movsb
  ret
error1:
  lea dx,message3
  mov ah,09h
  int 21h
  jmp next
puttele endp
;------------------------------sort by the name-----------------------------------------------
sort1 proc near 
  cmp totle,1
  jbe later
  sub di,56
  mov endtel,di
g20:
  mov swapped,0
  lea si,teletab
g30:
  mov cx,28
  mov di,si
  add di,28
  mov ax,di
  mov bx,si
  repe  cmpsb
  jbe g40
  call h10xchg
g40:
  mov si,ax
  cmp si,endtel
  jbe g30
  cmp swapped,0
  jnz g20
later:
  ret
sort1 endp
;-------------------------------exchange the set of name and the number-------------------------
h10xchg proc near
  mov cx,28
  lea di,telephsort
  mov si,bx
  rep movsb
  mov cx,28
  mov di,bx
  rep movsb
  mov cx,28
  lea si,telephsort
  rep movsb
  mov swapped,1
  ret
h10xchg endp 
;----------------------------------find the name-----------------------------------------------
research proc near
  lea dx,message6
  mov ah,09h
  int 21h
  lea dx,maxnlen
  mov ah,0ah
  int 21h
  mov bh,0
  mov bl,namelen
  mov cx,21
  sub cx,bx
b201:
  mov namefld[bx],20h
  inc bx
  loop b201
  mov bx,totle
  lea di,teletab
furth:
  mov ax,di
  lea si,namefld
  mov cx,0
  mov cl,20
  repe cmpsb
  je catch
  add ax,28
  mov di,ax
  dec bx
  jz nocatch
  jmp furth
catch:
  mov temp,ax
  lea dx,message7
  mov ah,09h
  int 21h
  lea di,telephsort
  mov si,temp
  mov cx,28
  rep movsb
  lea dx,telephsort
  mov ah,09h
  int 21h
  ret
nocatch:
  lea dx,message8
  mov ah,09h
  int 21h
  ret
research endp
;------------------------------------------------------------------------------------
code ends
  end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -