📄 music.asm
字号:
data segment
mess1 db ' Music List Management System',0ah,0dh,'$'
mess2 db 0ah,0dh,'Please input the name of the singer: $'
mess3 db 'The following songs belong to the singer $'
mess4 db 'Continue to search?(y/n) $'
err1 db 'The singer you want does not exist in the database!',0ah,0dh,'$'
err2 db ' file close wrong$'
fname db 'list.txt',0
buffer1 db 90 dup(?) ;读入的字符缓冲区
buffer2 db 95 dup(?) ;输出的字符缓冲区
count db 5
handle dw ?
del db 8 dup('0')
x db ?
data ends
;###########################################################################################
score struc
s db 15 dup(' ')
m1 db 15 dup(' ')
m2 db 15 dup(' ')
m3 db 15 dup(' ')
m4 db 15 dup(' ')
m5 db 15 dup(' ')
score ends
show macro addrs ;显示字符串
lea dx,addrs
mov ah,9
int 21h
endm
clear macro ;全屏幕清除
mov al,0
mov cl,0
mov ch,0
mov dh,24
mov dl,79
mov bh,7
mov ah,6
int 10h
endm
newline macro ;回车换行
push ax
push dx
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
pop dx
pop ax
endm
;-----------------------------------------------------------
show_item macro addrs
local iloop,w10,again,exits
push bx
push cx
mov bx,0
iloop: mov dl,addrs[bx] ;display char 输出addrs开始的15个字符
mov ah,2
int 21h
inc bx
cmp bx,15
jl iloop
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
mov cx,1
w10: mov si,15
cmp addrs[bx],' '
je exits
mov dl,' '
mov ah,2
int 21h
mov dl,cl
add dl,30h
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
again: mov dl,addrs[bx] ;输出addrs开始的15个字符
mov ah,2
int 21h
inc bx
dec si
jnz again
newline
inc cx
cmp cx,5
jle w10
exits: pop cx
pop bx
endm
;---------------------------------------------------------
getin macro addrs,count2
local zeroit,lp,input_end,exitm ;将count2个字符输入到addrs为首的内存单元当中,以回车换行作为终止,多余15个字符的忽略
push bx
push ax
mov bx,0 ;addrs为首的15个字符置为空格
zeroit: mov addrs[bx],' '
inc bx
cmp bx,15
jl zeroit
mov bx,0 ;将count2个字符输入到addrs为首的内存单元当中
lp: mov ah,1
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 exitm
cmp al,0ah
jz exitm
mov ah,7
int 21h ;无回显的键盘输入
jmp input_end
exitm:
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
again:
call query
newline
show mess4
mov ah,01h
int 21h
cmp al,'n'
je exit
newline
jmp again
exit: mov ah,4ch
int 21h
ret
main 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
;--------------------------------------------------------------
query proc near
push ax
push bx
push cx
push dx
call openf
show mess2
getin buffer1,15 ;从键盘读取15个字符(歌手名称)到首地址为buffer1缓冲区当中
newline
newline
r: mov ah,3fh ;从文件中读取90个字节到首地址为buffer2的缓冲区当中,每一项设定为90个字节
mov cx,90
mov dx,offset buffer2
int 21h
cmp ax,0
jne continue ;条件转移只能利用短跳转
jmp notfound
continue:
lea si,buffer2
lea di,buffer1
mov cx,15
c:
mov al,byte ptr[si]
cmp al,byte ptr[di]
jnz r
inc si
inc di
loop c
show mess3
show_item buffer2
jmp exitp
notfound:
show err1
exitp:
mov ah,3eh ;关闭文件
int 21h
pop dx
pop cx
pop bx
pop ax
ret
query endp
;--------------------------------------------------------
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -