📄 1.asm
字号:
jne qque
call inputnum
call inputsco
call stor
showmsg insed
mov saveflag,0
qque:
ret
bg_search endp
;------------------------------------------------------------------------
bg_modify proc near
;void modify()
push ax
push bx
push dx
showmsg menu5_1;display modify submenu
mov ah,1
int 21h;getch()
crlfm
cmp al,'1'
je t1
cmp al,'2'
je t2
mov bx,3
call inputsco
jmp cin
t1:
call inputname
mov bx,1
jmp cin
t2:
mov bx,2
call inputnum
cin:
push bx
call near ptr modify
cmp ax,-1
je qmodi
crlfm
showmsg moded
qmodi:
pop dx
pop bx
pop ax
ret
bg_modify endp
;------------------------------------------------------------------------
quit proc near
;quit program
cmp saveflag,0
je qforsav
jmp qsys
qforsav:
call clear
call cursor
showmsg qsave
mov ah,1
int 21h
cmp al,'y'
je savit
jmp qsys
savit:
call save
mov ah,3eh;close file
mov bx,filehandle
int 21h
qsys:
mov ax,4c00h
int 21h
ret
quit endp
;------------------------------------------------------------------------
;code ends
;codeproc segment
; assume cs:codeproc,ds:data
search proc near
;int search(int begin_addr,int type) 在表中顺序查找输入的名字,返回地址或-1
push bp
mov bp,sp
push di
push bx
push si
push cx
push dx
mov di,[bp+6] ;把查找首地址放入di
mov dx,stustored ;名字的个数放dh
mov bx,[bp+4];bx:type
mov bp,di
cmp bx,1
je snam
cmp bx,2
je snum
mov cx,3
mov bx,cx;dl:保存字符串比较长度
lea ax,scofld
jmp loop1
snam: mov cx,6
mov bx,cx
lea ax,namefld
jmp loop1
snum: mov cx,8
mov bx,cx
lea ax,numfld
loop1:
mov si,ax
mov cx,bx
repe cmpsb ;连续查找匹配名字
je found ;找到跳转found
add bp,17 ;把查找转到下一个名字
mov di,bp
dec dh
jnz loop1 ;循环查找
mov ax,-1
showmsg noext
jmp qsearch
found: mov ax,bp
mov dx,stustored
sub dx,bx
mov cur_i,dx
qsearch:pop dx
pop cx
pop si
pop bx
pop di
pop bp
ret 4
search endp
;------------------------------------------------------------------------
name_sort proc near
;void sort() 有交换标志的冒泡排序
;注意cmpsb过程中si,di指针的自动变化!
push si
push di
push ax
push bx
push dx
push cx
cmp stustored,1
je qsort ;比较名字个数,只有一个名字无需排序,退出
lea bx,studentx
push bx
mov ax,stustored
sub ax,1
mov bl,17
mul bl
pop bx
add bx,ax
mov dx,stustored
sub dx,1 ;dx:i,即循环次数
l1: mov swapped,0
sub bx,17;第一次指向倒数第二项,以后每跑一趟前移一项
mov endaddr,bx
push bx
lea si,studentx;si:j,j=0
l2: mov cx,6 ;置循环计数值
mov di,si
add di,17 ;di->后项,目标 si->前项,源
mov bx,di
mov ax,si
repe cmpsb ;源-目标,即前项如果大于后项,交换;
jbe s3
exchange ax,bx
s3: mov si,ax
add si,17;j++
cmp si,endaddr
jbe l2 ;是否已到循环表尾,如果没到继续循环
pop bx
cmp swapped,0 ;如果有交换,继续下一趟
je qsort
dec dx
jnz l1
qsort: pop cx
pop dx
pop bx
pop ax
pop di
pop si
ret
name_sort endp
;------------------------------------------------------------------------
del proc near
;int del() 返回-1或1
push bx
push di
push si
push cx
lea bx,studentx
push bx
mov bx,1;search(studentx,name)
push bx
call near ptr search
cmp ax,-1;先找到被删除项
je nomatch
mov di,ax
mov si,di
add si,17;si:j,di:i
mov cx,stustored;被删除项后面元素前移
sub cx,cur_i
movit:
movitem di,si
mov di,si;si:j+1 ,di:j
mov dx,di
add dx,17
mov si,dx
loop movit
mov ax,1
mov saveflag,0
sub stustored,1
nomatch:
pop cx
pop si
pop di
pop bx
ret
del endp
;------------------------------------------------------------------------
insert proc near
;void insert() 在studentx表尾插入一项
push si
push di
push ax
push bx
push cx
cmp stustored,0
je exi
lea si,stutemp
lea di,studentx
mov ax,stustored
mov bl,17
mul bl
add di,ax
mov cx,17;
rep movsb
inc stustored
exi: pop cx
pop bx
pop ax
pop di
pop si
ret
insert endp
;------------------------------------------------------------------------
stor proc near
;void stor() stor one item to studnetx tab from input buffer area
push ax
push bx
push dx
push di
push si
push cx
cmp namelen,0
je qsto
cld
mov ax,stustored
mov bl,17
mul bl
lea dx,studentx
mov stu,dx
add stu,ax
mov di,stu
lea si,namefld
mov cx,6
rep movsb
lea si,numfld
mov cx,8
rep movsb
mov cx,3
lea si,scofld
rep movsb
inc stustored
qsto:
pop cx
pop si
pop di
pop dx
pop bx
pop ax
ret
stor endp
;------------------------------------------------------------------------
modify proc near
;int modify(int type) 修改成功返回1,没有指定项返回-1
push bp
mov bp,sp
push bx
push dx
;push ax
push di
push cx
mov bx,[bp+4]
cmp bx,1
je mdnam
cmp bx,2
je mdnum
lea dx,studentx+14
jmp find
mdnam:
lea dx,studentx
jmp find
mdnum:
lea dx,studentx+6
find:
push dx
push bx
call near ptr search
cmp ax,-1
je qu_mod
mov di,ax;
cmp bx,1
je mnam
cmp bx,2
je mnum
lea dx,msg_nsco
mov ah,9
int 21h
lea dx,scopar
mov ah,0ah
int 21h
mov cx,3
lea si,scofld
jmp mfy
mnam:
lea dx,msg_nname
mov ah,9
int 21h
call inputname
mov cx,6
lea si,namefld
jmp mfy
mnum:
lea dx,msg_nnum
mov ah,9
int 21h
lea dx,numpar
mov ah,0ah
int 21h
mov cx,8
lea si,numfld
mfy:
rep movsb
mov saveflag,0
mov ax,1
qu_mod:
pop cx
pop di
;pop ax
pop dx
pop bx
pop bp
ret 2
modify endp
;------------------------------------------------------------------------
stat proc near
;void stat()
push cx
push bx
push dx
push ax
mov cx,stustored
lea bx,[studentx+14];成绩域第一项地址
sta:
mov dx,[bx];前面两个数字
mov ah,[bx+2];最低位数字,均为ASCII码
cmp dl,'1'
je a90
cmp dh,'9'
jae a90
cmp dh,'8'
jae a80
cmp dh,'7'
jae a70
cmp dh,'6'
jae a60
add b60,1
jmp repeat
a90:add ae90,1
jmp repeat
a80:add ae80,1
jmp repeat
a70:add ae70,1
jmp repeat
a60: add ae60,1
repeat:add bx,17
loop sta
showmsg stattit
showmsg _titleln
showmsg _b60
mov bl,byte ptr b60
call deciasc
crlfm
showmsg _titleln
showmsg _ae60
mov bl,byte ptr ae60
call deciasc
crlfm
showmsg _titleln
showmsg _ae70
mov bl,byte ptr ae70
call deciasc
crlfm
showmsg _titleln
showmsg _ae80
mov bl,byte ptr ae80
call deciasc
crlfm
showmsg _titleln
showmsg _ae90
mov bl,byte ptr ae90
call deciasc
crlfm
showmsg _titleln
mov ae90,0;统计变量清0
mov ae80,0
mov ae70,0
mov ae60,0
mov b60,0
pop ax
pop dx
pop bx
pop cx
ret
stat endp
;-------------------------------------------------------------------
errm proc near
;磁盘操作的容错处理
push ax
mov ah,9
int 21h
mov errcde,01
pop ax
ret
errm endp
;-------------------------------------------------------------------
input proc near
;void input() 通过键盘输入一条item并保存在内存studentx表中
push ax
push dx
call near ptr clear ;清理屏幕
call near ptr cursor ;设置光标
cmp stustored,29
ja i1
mov ah,09
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -