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

📄 lm3.asm

📁 这是汇编课程设计的题目,内含有五个程序:图书管理系统,字符统计等.
💻 ASM
字号:
STACK SEGMENT PARA STACK 'STACK'
        DW 128 DUP(?)
STACK ENDS
;**************************************************************
string	macro	xp			      	        ;宏定义,输出提示字符串
	push	dx
	push	ax
	mov	ah,9
	lea	dx,str&xp
	int	21h
	pop	ax
	pop	dx
	endm
;**************************************************************
EXTRA SEGMENT PARA 'EXTRA'

EXTRA ENDS
;**************************************************************

DATA SEGMENT PARA 'DATA'                         
str0 db 0ah,0dh,'* * * *  Choose * * * *','$'            ;数据均在数据段操作
str1 db 0ah,0dh,'* * *   i.insert  * * *','$'
str2 db 0ah,0dh,'* * *   f.search  * * *','$'
str3 db 0ah,0dh,'* * *   s.sort    * * *','$'
str4 db 0ah,0dh,'* * *   q.exit    * * *','$'
str5 db 0ah,0dh,'* * * * * * * * * * * *',0ah,0dh,'$'
str6 db 0ah,0dh,'* * * Singer  :','$'
str7 db 0ah,0dh,'* * * Song(s) :','$'
str8 db 0ah,0dh,'* * * No Match!',0ah,0dh,'$'
str9 db 0ah,0dh,'* * * Sort finished!','$'
str10 db 0ah,0dh,'* * * Input the name:','$'

messg db 50 dup(?)
geshu dw 0
num dw 0
array db 30 dup(50 dup(20h))
namesav db 10 dup(20h)
char db '$'
songsav db 40 dup(20h)
char1 db '$'
mshu dw 0
biaozhi dw -1
DATA ENDS


;***************************************************************
CODE SEGMENT PARA 'CODE'
    ASSUME CS:CODE,DS:DATA,SS:STACK,ES:EXTRA
MAIN PROC FAR
START:
        MOV AX,DATA
        MOV DS,AX  ;Let DS register have data segment address
        MOV AX,EXTRA
        MOV ES,AX  ;Let ES register have extra segment address
;**************************************************************
       
lop:  string 0                               ;提示菜单
      string 1
      string 2
      string 3
      string 4
      string 5

      mov ah,01
      int 21h

l1:   cmp al,'i'                             ;通过输入(i,f,s,q)调用功能模块
      jnz l2
      call insert
l2:   cmp al,'f'
      jnz l3
      call search
l3:   cmp al,'s'
      jnz l4
      call display
l4:   cmp al,'q'
      jnz  lop                                ;输入非功能键时跳回菜单

;***************************************************************
        MOV AH,4CH ;DOS function call
        INT 21H ;Return to DOS
MAIN ENDP                                      ;主程序结束
;---------------------------------------------------------------


insert proc near

        push si                                 ; 先将要使用的寄存器压入栈
        push di
        push dx
        push ax
        push cx

        mov  si,0
        mov  di,si
        mov  bx,50                               ;记录的长度固定
        mov  ax,geshu                                       
        mul  bx                                   ;插入新的记录时在字符串中的起始地址
        mov  si,ax

        mov  di,si
        mov  cx,10
        string 6                                   ;输入演唱者的名字,名字长度为固定值10
inname:
        mov  ah,01
        int  21h
        cmp  al,13
        jz   ins 
        mov  byte ptr array[si],al    
        inc  si
        loop inname

ins:
        add  di,9                                  ;输入演唱者的所有歌曲,有40个字节空间
        mov  si,di
        mov  cx,30  
        string 7
iloop:  inc  si
        mov  ah,01
        int  21h
        cmp  al,13
        jz   i_end
        mov  byte ptr array[si],al
        loop iloop

i_end:  add  geshu,1                                 ;记录演唱者的个数
        call sort
     

        pop  cx                                       ;将所有用到的寄存器按顺序出栈
        pop  ax
        pop  dx
        pop  di
        pop  si
      
        ret
insert endp
;-----------------------------------------------------------------
search proc near
       push  dx                                         ; 先将要使用的寄存器压入栈
       push  cx
       push  ax 
       push  bx
       push  si
       push  di

       mov   si,0
       mov   di,si
       mov   bx,si
       mov   ax,geshu                                             
       mov   num,ax
       string 10
f1:
       mov   ah,01                                        ;接收要查找的演唱者名字,并将其逐个字符送入缓冲区中
       int   21h
       mov   byte ptr namesav[di],al
       cmp   al,13
       jz    f2
       inc   di
       jmp   f1
f2:    mov   ax,10
       sub   ax,di
       mov   bx,ax
      
f3:    mov   namesav[di],20h                               ;将未满10个字节的名字用20H填满,便于比较
       inc   di
       dec   bx
       jnz   f3
       lea   di,array
       mov   bx,0
f4:    lea   di,array                                       ;用si,di来进行逐字符的比较
       mov   cx,10
       add   di,bx
       lea   si,namesav
       repe  cmpsb
       jz    find                                           ;查到记录时,将该演唱者的所有歌曲全部输出

f5:    mov   cx,50                                           
       dec   num
       jz    no_match
       mov   ax,geshu
       sub   ax,num
       mul   cx
       mov   bx,ax
       jmp   f4                                             ;用个数当循环控制条件   
find:  mov   cx,50
       mov   ax,geshu
       sub   ax,num
       mul   cx
       mov   di,ax
       lea   si,array                                       ;查找时记录的演唱者在字符串中的第i个,并将50当乘积因子  
       add   si,di
       mov   biaozhi,si
       string 6
       lea   di,namesav
       mov   cx,10
       rep   movsb
       mov   ah,9
       lea   dx,namesav
       int   21h
       
       string 7
       lea   di,songsav
       mov   cx,40
       rep   movsb
       mov   ah,9
       lea   dx,songsav
       int   21h
       jmp   f_end

no_match:
       string 8
f_end:
       pop   di                                          ;将所有用到的寄存器按顺序出栈
       pop   si
       pop   bx 
       pop   ax 
       pop   cx
       pop   dx
       ret
search endp
;------------------------------------------------------------------------
sort proc near
       push  di
       push  si
       push  bx
       push  ax
       push  cx
       push  dx

       mov   dx,geshu                                     ;将演唱者的个数作为外循环
       cmp   geshu,1
       jz    s_end
  
s1:
       dec   dx
       jz    s_end
       mov   bx,geshu
       dec   bx
       lea   si,array
s2:
       mov   cx,10                                        ;将名字的固定长度作为内层循环的控制条件
       mov   di,si
       add   di,50
       mov   ax,di
       mov   num,si
       repe  cmpsb
       jbe   s3                                            ;不转换存储位置
       call  hxchg                                         ;调用hxchg程序,转换存储位置
    
s3:    dec   bx                                                             
       jz    s1
       mov   si,ax
       jmp   s2
s_end: 
       string 9
       pop  dx
       pop  cx
       pop  ax
       pop  bx
       pop  si
       pop  di
       ret
sort endp
;--------------------------------------------------------------------------
hxchg proc near
       push  si
       push  di
       push  bx
       push  ax
       push  cx

       mov   cx,50                                  ;将名字较低的字符(固定长度50db)送到messg中保存
       lea   di,messg
       mov   si,num
       rep   movsb

       mov   cx,50                                  ;将名字较高的字符送到名字较低的存储区中
       mov   di,num
       rep   movsb

       mov   cx,50                                  ;将保存的名字低位的字符送到名字较高的存储区中
       lea   si,messg
       rep   movsb
            
       pop   cx
       pop   ax
       pop   bx
       pop   di
       pop   si
       ret
hxchg endp
;-------------------------------------------------------------------------

display proc near
       push  si
       push  di
       push  bx
       push  ax
       push  cx
     
     
       mov   bx,geshu                              ;用个数当输出排序结果的循环控制条件
       mov   si,0
       mov   di,si
       cld 
       lea   si,array
       
  
print:  
       string 6                                     ;输出演唱者的名字
       lea   di,namesav
       mov   cx,10
       rep   movsb
       mov   ah,9
       lea   dx,namesav
       int   21h
       
       string 7                                      ;输出对应歌手的所有歌曲
       lea   di,songsav
       mov   cx,40
       rep   movsb
       mov   ah,9
       lea   dx,songsav
       int   21h
        
       dec   bx
       jnz   print
 
       pop   cx
       pop   ax
       pop   bx
       pop   di
       pop   si
       ret
display endp

;*********************************************************************************
CODE ENDS                                              ;子程序结束
        END START


⌨️ 快捷键说明

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