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

📄 book.asm

📁 汇编语言课程设计的程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
       show err3             ;文件输入错误     
i1:    mov ah,3eh             ;关闭文件
       int 21h
       show messsuc
       show messrtn
       mov ah,07h
       int 21h
       showmenu
       
       pop dx
       pop cx
       pop bx
       pop ax
       ret
insert endp

;--------------------------------------------------------------
query  proc near  ;查询图书信息
       push ax
       push bx
       push cx
       push dx
       
       clear
       show messqur
       call openf
       getin buffer1,nno ;从键盘读取15个字符(图书名称)到首地址为buffer1缓冲区当中
       newline
       
b:     mov ah,3fh    ;从文件中读取itemno个字节到首地址为buffer2的缓冲区当中,每一项设定为itemno个字节
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       cmp ax,0
       je  notfound
       
       lea si,buffer2
       lea di,buffer1
       mov cx,nno 
c:     mov al,byte ptr[si] 
       cmp al,byte ptr[di]
       jnz b
       inc si
       inc di
       loop c
       
       show messrlt
       show mess11
       ;mov [buffer2+itemno],'$'
       show_item buffer2
       jmp exit
       
notfound:
       show err1
exit:  
       mov ah,3eh      ;关闭文件
       int 21h
       show messrtn
       mov ah,07h
       int 21h
       showmenu
       pop dx 
       pop cx
       pop bx
       pop ax
       ret
query  endp
;--------------------------------------------------------
modify  proc near  ;修改更新已存在的图书信息
       push ax
       push bx
       push cx
       push dx
       
       clear
       show messqur
       call openf
       getin buffer1,nno ;从键盘读取15个字符(图书名称)到首地址为buffer1缓冲区当中
       newline
       
b1:     mov ah,3fh    ;从文件中读取itemno个字节到首地址为buffer2的缓冲区当中,每一项设定为itemno个字节
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       cmp ax,0
       jne  found1
       jmp  notfound1
found1:       
       lea si,buffer2
       lea di,buffer1
       mov cx,nno 
c1:    mov al,byte ptr[si] 
       cmp al,byte ptr[di]
       jnz b1
       inc si
       inc di
       loop c1
       
       show messrlt
       show mess11
      ; mov [buffer2+itemno],'$'
       show_item buffer2
       show messmdf
       call get_rec          ; contact is in  buffer1
       mov bx,handle
       mov ah,42h
       mov al,1   ;相对移动方式移动文件指针
       mov cx,0ffffh  ;偏移指针的高位字
       mov dx,-itemno
       int 21h
       
       mov cx,itemno
       mov dx,offset buffer1
       mov ah,40h
       int 21h         ;将buffer1当中内容存入文件
       newline
       newline
       show messsuc
       jmp exit11
       
notfound1:
       show err1
exit11:  
       mov ah,3eh      ;关闭文件
       int 21h
       show messrtn
       mov ah,07h
       int 21h
       showmenu
       pop dx 
       pop cx
       pop bx
       pop ax
       ret
modify  endp
;---------------------------------------------------------------
delete proc near   ;删除已存在的图书信息
       push ax
       push bx
       push cx
       push dx
              
       clear
       show messqur
       call openf     ;打开数据文件
       
       mov dx,offset ftmp  ;创建临时文件
       mov cx,02   ;隐藏属性的临时文件
       mov ah,3ch
       int 21h
       mov htmp,ax
       
       getin buffer1,nno ;从键盘读取nno个字符(图书名称)到首地址为buffer1缓冲区当中
       newline
       
b2:    mov bx,handle
       mov ah,3fh    ;从handle代表的文件中读取itemno个字节到首地址为buffer2的缓冲区当中,每一项设定为itemno个字节
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       cmp ax,0
       jne  found2
       jmp  notfound2
found2: 
       mov ah,40h    ;将首地址为buffer2缓冲区的itemno个字符写入htmp所代表的文件当中
       mov bx,htmp
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       
       lea si,buffer2
       lea di,buffer1
       mov cx,nno 
c2:    mov al,byte ptr[si] 
       cmp al,byte ptr[di]
       jnz b2
       inc si
       inc di
       loop c2
       
       show messrlt
       show mess11
       ;mov [buffer2+itemno],'$'
       show_item buffer2
       show messdm
       mov ah,1   ;带回显的键盘输入
       int 21h
       cmp al,'n'
       je  exit22
       ;删除操作:临时文件的文件指针前移itemno个字符,之后将现有文件所有剩余字符写入临时文件
       mov bx,htmp    ;临时文件指针前移itemno位
       mov ah,42h
       mov al,1   ;相对移动方式移动文件指针
       mov cx,0ffffh  ;偏移指针的高位字
       mov dx,-itemno
       int 21h
       
again2:                ;将现有文件中其他字节存入到临时文件当中
       mov bx,handle
       mov ah,3fh    ;从现有文件中读取itemno个字节到首地址为buffer2的缓冲区当中,每一项设定为itemno个字节
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       cmp ax,0   ;ax=0表示已经读到文件末尾
       je  continue2
       mov ah,40h    ;将首地址为buffer2缓冲区的itemno个字符写入htmp所代表的文件当中
       mov bx,htmp
       mov cx,itemno
       mov dx,offset buffer2
       int 21h
       jmp again2
        
continue2:
       mov bx,handle
       mov ah,3eh      ;关闭文件
       int 21h
       mov bx,htmp
       mov ah,3eh      ;关闭文件
       int 21h
       
       mov dx,offset fname   ;删除现存文件
       mov ah,41h
       int 21h
       mov dx,offset ftmp   ;将临时文件名修改为数据文件名
       mov di,offset fname
       mov ah,56h
       int 21h
       
       show messsuc
       jmp exit22       
notfound2:
       show err1
exit22:
       show messrtn
       mov ah,07h
       int 21h
       showmenu


       pop dx
       pop cx
       pop bx
       pop ax
       ret
delete endp             

;--------------------------------------------------------------
get_rec proc near   ;输入图书信息到buffer1当中
       push ax
       push bx
       
       show messn           ;输入 图书名称 nno个字符到buffer1当中
       getin buffer2,nno  ;将15个字符输入到buffer2为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
       mov bx,0
       mov  cx,15
continue11:   
       mov al,buffer2[bx]   ;起始地址为buffer2的15个字符复制到起始地址为buffer1的内存单元当中
       mov buffer1[bx],al
       inc bx
       loop  continue11
             
       newline
       show messa          ;输入 图书作者 ano个字符到buffer1当中
       getin buffer2,ano  ;将ano个字符输入到buffer2为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
       mov  si,0
continue22:   
       mov al,[buffer2+si]   ;起始地址为buffer2的15个字符复制到起始地址为buffer1的内存单元当中
       mov buffer1[bx],al
       inc bx
       inc si
       cmp si,ano
       jl  continue22
       
       newline
       show messpub         ;输入 出版社 pno个字符到buffer1当中
       getin buffer2,pno  ;将pno个字符输入到buffer2为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
       mov  si,0
continue33:   
       mov al,[buffer2+si]   ;起始地址为buffer2的15个字符复制到起始地址为buffer1的内存单元当中
       mov buffer1[bx],al
       inc bx
       inc si
       cmp si,ano
       jl  continue33
              
       newline
       show messi         ;输入 ISBN ino个字符到buffer1当中
       getin buffer2,ino  ;将15个字符输入到buffer2为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
       mov  si,0
continue44:   
       mov al,[buffer2+si]   ;起始地址为buffer2的15个字符复制到起始地址为buffer1的内存单元当中
       mov buffer1[bx],al
       inc bx
       inc si
       cmp si,ano
       jl  continue44
      
       newline
       show messprc         ;输入 价格 prcno个字符到buffer1当中
       getin buffer2,prcno  ;将prcno个字符输入到buffer2为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
       mov  si,0
continue55:   
       mov al,[buffer2+si]   ;起始地址为buffer2的15个字符复制到起始地址为buffer1的内存单元当中
       mov buffer1[bx],al
       inc bx
       inc si
       cmp si,ano
       jl  continue55
      
       newline
       pop bx
       pop ax
       ret
get_rec endp
;-----------------------------------------------------------
openf proc near    ;打开fname所确定的文件,文件代号存入handle当中
      mov dx,offset fname
      mov al,02
      mov ah,3dh
      int 21h
      mov handle,ax
      mov bx,ax    ;失之毫厘,谬以千里
      ret
openf endp
;----------------------------------------------------------------
help proc near   ;显示帮助信息
      clear
      set_p0
      show w1
      show w2
      show w3
      show w4
      mov ah,07h
      int 21h
      clear
      showmenu
      newline
      
      ret
help endp
;----------------------------------------------------------------
code   ends
       end start

⌨️ 快捷键说明

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