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

📄 接近完美的源代码电话号码查询.asm

📁 程序控制只能输入不超过15个字母的名字,电话号码只能为4位
💻 ASM
字号:
data    segment
mess1   db '          student grade management system',0ah,0dh,'$'
mess2   db '           this is main menu',0ah,0dh,'$'
mess3   db '           insert  (i)    please input:',0ah,0dh,'$' 
mess4   db '           query (q)      Name :',0ah,0dh,'$'
mess5   db '           exit   (e)     Phonumber:',0ah,0dh,'$'
mess10  db '**********************************************************$'
mess11  db 'Name         Phonumber',0ah,0dh,'$'
mess13  db '           list    (l)',0ah,0dh,'$'
err1    db '              there is no this student$'
err2    db '               file close wrong$'
fname   db "c:\asm\score.txt"
buffer1 db 19 dup(?)
buffer2 db 30 dup(?)
buffer3 db 4 dup('0')
count   db 5
handle  dw ?
del     db 4 dup('0')
x       db ?
data    ends

score struc
names    db 15 dup(' ')
Phonumber    db 0,0
score ends

show macro addrs
        lea dx,addrs
        mov ah,9
        int 21h
        endm

set_p1 macro  a
        mov ah,2
        mov dh,a    
        mov dl,36
        mov bh,0
        int 10h       ;置光标位置在bh页,行为dh,列为dl处
        endm

set_p2 macro
       mov ah,2
       mov dh,8
       mov dl,2
       mov bh,0
       int 10h        ;置光标位置在bh页,行为dh,列为dl处
       endm
set_p3 macro
       mov ah,2
       mov dh,1
       mov dl,30
       mov bh,0
       int 10h       ;置光标位置在0页,第1行,第30列   
       endm

clear  macro                        ;all screen
       mov al,0
       mov cl,0
       mov ch,0
       mov dh,24
       mov dl,79
       mov bh,7
       mov ah,6
       int 21h                        
       endm

clear1 macro                   ;left screen
       mov al,0
       mov bh,7        ;空留区填充字符的属性
       mov ch,4
       mov cl,36
       mov dh,10
       mov dl,79
       mov ah,6
       int 10h      ;屏幕向上滚动,ch左上角行座标cl列座标,dh右下角行座标dl列座标
       endm

clear2 macro                      ;down screen
       mov al,0
       mov bh,7      ;空留区填充字符的属性
       mov ch,12
       mov cl,0
       mov dh,24
       mov dl,79
       int 10h     ;屏幕向上滚动,ch左上角行座标cl列座标,dh右下角行座标dl列座标
       endm

newline macro    ;换两行
        push ax
        push dx
        mov dl,0dh
        mov ah,2
        int 21h        ;显示输出,dl 为显示的字符,回车
        mov dl,0ah
        mov ah,2
        int 21h        ;显示输出,dl 为显示的字符,换行
        pop dx
        pop ax
        endm

show_item macro addrs    ;显示一条记录
        local iloop,w10
        push bx
        push cx
        mov bx,0
iloop:  mov dl,addrs[bx]         ;display char
        mov ah,2
        int 21h             ;显示addrs中的姓名
        inc bx
        cmp bx,15      
        jl  iloop
        mov cx,4

w10:    
        mov dl,addrs[bx]
        mov ah,2
        int 21h           ;显示剩下的4个字符
        inc bx
        mov dl,addrs[bx]
        mov ah,2
        int 21h
        inc bx      
        loop  w10   ;loop每执行一次,cx减1,循环4次
        newline      ;换两行
        pop cx
        pop bx
        endm

getin   macro addrs,count2
local   zeroit,lp,input_end,exit
        push bx
        push ax
        mov bx,0

zeroit:
         mov addrs[bx],' '
         inc bx
        cmp bx,count2  ;姓名的最大长度
        jl  zeroit

        mov bx,0
lp:     mov ah,1 ;接收字符放入al 中,并且输入的字符显示出来
        int 21h
        cmp al,0ah  ;比较输入的字符是否为换行
        jz  input_end
        cmp al,0dh  ;比较输入的字符是否为回车
        jz  input_end
        mov addrs[bx],al  ;将输入的字符放入
        inc bx
        cmp bx,count2  ;比较字符的数目是否大于要控制的长度
        jl lp

input_end: 
       cmp al,0dh  ;如果是回车
        jz  exit
        cmp al,0ah  ;如果是换行
        jz  exit
        mov ah,7     ;接收输入的字符,放入al中并且输入的字符不显示出来
        int 21h
        jmp input_end   
exit:   
        pop ax
        pop bx
        endm


code    segment
main proc far
     assume  cs:code,ds:data,es:data

start: 
      mov ax,data
      mov ds,ax
      mov ah,0
      mov al,3
      int 10h
     
      clear
      show mess1
      show mess2
      show mess13
      show mess3
      show mess4
      show mess5
      newline
      show mess10
      set_p3        ;设置光标位置
w:    mov ah,7
      int 21h       ;接收输入的字符放入al中
      cmp al,'i' 
      jnz n1            
      call insert
      jmp  w
n1:   cmp al,'q'
      jnz  n2
      call query  ;调用按姓名查找子程序
      set_p3       ;设置光标位置
      jmp  w
n2:   cmp  al,'l'
      jnz  n3
      call list
      set_p3    ;设置光标位置
      jmp  w
n3:   cmp al,'e'
      jz  exitf
      jmp  w
exitf:
       mov ah,4ch
       int 21h
       ret
main   endp

insert proc near
       push ax
       push bx
       push cx
       push dx
      
       mov dx,offset fname
       mov al,2    ;以读写方式
       mov ah,3dh
       int 21h           ;以读写方式打开文件
       mov bx,ax
       clear1
       set_p1 4
       call get_rec
  
       mov cx,0               ;move file pointer to end
       mov dx,0
       mov al,2
       mov ah,42h
       int 21h      

    
       mov cx,19                    ;write file
       mov dx,offset buffer1
       mov ah,40h 
       int 21h                     ;写文件
       mov ah,3eh
       int 21h                     ;关闭文件
       set_p3
       pop dx
       pop cx
       pop bx
       pop ax
       ret
insert endp

get_rec proc near
       push ax
       push bx
       getin buffer2,15 ;控制输入15个字符放入buffer2中
       mov bx,0      
       mov  cx,15     

continue:   mov al,buffer2[bx]
       mov buffer1[bx],al
       inc bx                             ;将bx连加直到它变成15为止
       loop  continue

       set_p1 5

       getin buffer2,4            ;锁定电话的号码的长度为4
       mov al,buffer2            ;第一个电话号码字符
       mov buffer1[bx],al
       inc bx
       mov al,buffer2+1       ;第二个电话号码字符
       mov buffer1[bx],al
       inc bx
       mov al,buffer2+2      ;第三个电话号码字符
       mov buffer1[bx],al
       inc bx
       mov al,buffer2+3      ;第四个电话号码字符
       mov buffer1[bx],al
       inc bx
                                              
       
       pop bx
       pop ax
       ret
get_rec endp

openf proc near
      mov dx,offset fname
      mov al,02
      mov ah,3dh
      int 21h         ;以读写方式打开文件
      mov handle,ax
      ret
openf endp

query  proc near
       push ax
       push bx
       push cx
       push dx
       clear1
       clear2      
       mov dx,offset fname
       mov al,2
       mov ah,3dh
       int 21h    ;以读写方式打开文件
       mov bx,ax
       set_p2
       getin buffer1,15   
       lea dx,mess11
       mov ah,9
       int 21h     ;显示字符串,dx为首地址
b:  
       mov ah,3fh
       mov cx,19   ;字节数
       mov dx,offset buffer2
       int 21h       ;读文件,读19个字符
       lea si,buffer2
       lea di,buffer1   ;取名字的首地址
       mov cx,15
c: 
       mov al,byte ptr[si]    ;将si强制转换为字节
       cmp al,byte ptr[di]    ;将di强制转换为字节,并比较
       jnz b                            
       inc si
       inc di
       loop c
       mov [buffer2+19],' '
       show_item buffer2    ;显示buffer2中的记录
       mov ah,3eh
       int 21h
       pop dx 
       pop cx
       pop bx
       pop ax
       ret
query  endp        

list   proc   near
       push ax
       push bx
       push cx
       push dx
      
       clear1
       clear2
       set_p2
       show mess11
       mov dx,offset fname
       mov al,2
       mov ah,3dh
       int 21h         ;以读写方式打开文件fname
       mov bx,ax
again: 
       mov dx,offset buffer1
       mov cx,19
       mov ah,3fh
       int 21h        ;读文件中的19个字符
       cmp ax,0
       jz p
       show_item buffer1  ;显示buffer1中的记录
       jmp again
p:         
       mov ah,3eh
       int 21h        ;关闭文件
       set_p3
       pop dx
       pop cx
       pop bx
       pop ax
       ret
list   endp
code   ends
       end start

       




    

⌨️ 快捷键说明

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