您的位置:首页 > 其它

用汇编实现学生信息管理系统

2012-12-15 21:57 711 查看
用汇编实现学生信息管理系统

;经过一番努力终于完成了所有的功能,哈哈哈
.model small
student struct
id db 4 dup(?)
score db 4 dup(?)
rank db 4 dup(?)
student ends
.data
str0 db ' Welcome to the student information management system',10,13,'$'
str1 db ' *************Menu******************',10,13,'$'
str3 db ' 1 **addition**',10,13,'$'
str11 db ' 2 **View**',10,13,'$'
str12 db ' 3 **delete**',10,13,'$'
str13 db ' 4 **insert**',10,13,'$'
str14 db ' 5 **find**',10,13,'$'
str4 db ' 6 **exit**',10,13,'$'
str5 db 'Please input file-path name!',10,13,'$'
str6 db 'Please input id:',10,13,'$'
str7 db 'Please input score:',10,13,'$'
str8 db 'continue or not(y/n)',10,13,'$'
str9 db 'ID score rank',10,13,'$'
str10 db ' $'
str2 db 'Find Results:',10,13,'$'
str15 db 'NOT Find!',10,13,'$'
str16 db 'Deleted successfully!',10,13,'$'
str17 db 'Not Find,delete failed!',10,13,'$'
file_path db 100,?,100 dup(?)
temp db 5,?,5 dup(?)
handle dw ?
person student 30 dup(<>)
person1 student <>
count dw 0
temp1 db ?
direction db ?
is_find db ?
.code
;程序功能:delete
;入口参数:
;出口参数:
delete proc
push ax
push bx
push cx
push dx
cmp count,0
jz over
lea dx,str6
mov ah,09h
int 21h
call input
mov direction,1
call read
mov cx,count
mov di,0
mov is_find,0
@@:
xor ah,ah
mov al,temp+1
mov bx,0
mov temp1,0
p131:
mov dl,temp[bx+2]
cmp dl,person[di+bx]
jnz p132
inc bx
dec al
cmp al,0
jnz p131
mov temp1,1
p132:
cmp temp1,0
jz p133
inc is_find
jmp p134
p133:
add di,0ch
loop @B
p134:
cmp is_find,0
jnz p135
lea dx,str17
mov ah,9h
int 21h
jmp over
p135:
mov ax,di
mov cx,count
mov bh,12
div bh
xor ah,ah
sub cx,ax
dec cx
cmp cx,0
jz p137
p136:
call move
add di,12
loop p136
p137:
dec count
lea dx,str16
mov ah,9h
int 21h
call sort
call write
over:
pop dx
pop cx
pop bx
pop ax
ret
delete endp
;程序功能:移动学生数据
;入口参数:di要移动的数据的地址,direction移动反向(1向前/0向后)
;出口参数:
move proc
push ax
push bx
push cx
cmp direction,0
jnz @F
mov cx,12
mov bx,0
s1:
mov al,person[di][bx]
mov person[di+12][bx],al
inc bx
loop s1
jmp exit
@@:
mov cx,12
mov bx,0
s2:
mov al,person[di+12][bx]
mov person[di][bx],al
inc bx
loop s2
exit:
pop cx
pop bx
pop ax
ret
move endp
;程序功能:find
;入口参数:
;出口参数:
find proc
push ax
push bx
push cx
push dx
cmp count,0
jz p35
lea dx,str6
mov ah,09h
int 21h
call input
lea dx,str2
mov ah,09h
int 21h
call read
mov cx,count
mov di,0
mov is_find,0
@@:
xor ah,ah
mov al,temp+1
mov bx,0
mov temp1,0
p31:
mov dl,temp[bx+2]
cmp dl,person[di+bx]
jnz p32
inc bx
dec al
cmp al,0
jnz p31
mov temp1,1
p32:
cmp temp1,0
jz p33
inc is_find
lea dx,person[di].id
mov ah,09h
int 21h
call ttab
lea dx,person[di].score
mov ah,09h
int 21h
call ttab
lea dx,person[di].rank
mov ah,09h
int 21h
call tap
jmp p34
p33:
add di,12
loop @B
p34:
cmp is_find,0
jnz p35
lea dx,str15
mov ah,09h
int 21h
p35:
pop dx
pop cx
pop bx
pop ax
ret
find endp
;程序功能:成绩排名
;入口参数:学生人数count
;出口参数:无
sort proc
push cx
push bx
mov di,4
mov bx,count
@@:
mov cx,count
call compare
add di,8
dec bx
jnz @B
pop bx
pop cx
ret
sort endp
;程序功能:rank compare
;入口参数:cx,di
;出口参数:无
compare proc
push bx
push dx
mov si,4
mov bl,1
p11:
call cmp1
cmp dl,0
jge p12
inc bl
p12:
add si,12
loop p11
add di,4
call data_str
pop dx
pop bx
ret
compare endp
;程序功能:数字转化为字符
;入口参数:bl
;出口参数:person[di].rank
data_str proc
push ax
push bx
push cx
push dx
.IF bl<10
mov cl,1
.else
mov cl,2
.endif
mov dl,cl
@@:
mov al,bl
mov ah,0
mov bh,10
div bh
xchg ah,al
mov bl,ah
mov ah,0
add al,'0'
push ax
loop @B
mov bx,0
mov cl,dl
@@:
pop ax
mov person[di+bx],al
inc bx
loop @B
mov al,'$'
mov person[di+bx],al
pop dx
pop cx
pop bx
pop ax
ret
data_str endp
;程序功能:比较大小
;入口参数:person.score,di,si
;出口参数:cx
cmp1 proc
push ax
push bx
push cx
mov bx,0
mov al,person[di+bx]
.while al!='$'
inc bx
mov al,person[di+bx]
.endw
mov cl,bl
mov bx,0
mov al,person[si+bx]
.while al!='$'
inc bx
mov al,person[si+bx]
.endw
cmp cl,bl
jl p1
jg p2
mov bx,0
@@:
mov al,person[di+bx]
cmp al,person[si+bx]
jl p1
jg p2
inc bx
loop @B
mov dl,0
jmp p3
p1:
mov dl,-1
jmp p3
p2:
mov dl,1
jmp p3
p3:
pop cx
pop bx
pop ax
ret
cmp1 endp
;程序功能:show
;入口参数:person
;出口参数:无
ttab proc
push ax
push dx
lea dx,str10
mov ah,09h
int 21h
pop ax
pop dx
ret
ttab endp
;程序功能:show
;入口参数:person
;出口参数:无
show proc
push ax
push bx
push cx
push dx
cmp count,0
jz over2
call read
lea dx,str9
mov ah,09h
int 21h
mov cx,count
mov di,0
@@:
lea dx,person[di].id
mov ah,09h
int 21h
call ttab
lea dx,person[di].score
mov ah,09h
int 21h
call ttab
lea dx,person[di].rank
mov ah,09h
int 21h
call tap
add di,12
loop @B
over2:
pop dx
pop cx
pop bx
pop ax
ret
show endp
;程序功能:inpue
;入口参数:temp
;出口参数:temp
input proc
push ax
push dx
lea dx,temp
mov ah,0ah
int 21h
call tap
pop dx
pop ax
ret
input endp
;程序功能:tmpe->person
;入口参数:temp,person
;出口参数:-
copy proc
push ax
push bx
push cx
push dx
mov al,12
mov bx,count
mul bl
mov si,ax
bg:
lea dx,str6
mov ah,09h
int 21h
call input
mov bx,0
mov cl,temp+1
@@:
mov al,temp[bx+2]
mov person[si+bx],al
inc bx
loop @B
mov al,'$'
mov person[si+bx],al
lea dx,str7
mov ah,09h
int 21h
call input
mov bx,0
mov cl,temp+1
add si,4
@@:
mov al,temp[bx+2]
mov person[si+bx],al
inc bx
loop @B
mov al,'$'
mov person[si+bx],al
inc count
add si,8
lea dx,str8
mov ah,09h
int 21h
mov ah,01h
int 21h
call tap
cmp al,'y'
jz bg
call sort
call write
pop dx
pop cx
pop bx
pop ax
ret
copy endp
;程序功能:回车换行
;入口参数:无
;出口参数:只在显示器上显示
tap proc
push ax
push dx
mov dl,0ah
mov ah,2h
int 21h
mov dl,0dh
mov ah,2h
int 21h
pop dx
pop ax
ret
tap endp
;程序功能:输出菜单信息
;入口参数:菜单信息的首地址放在DX中
;出口参数:只在显示器上显示
outstr proc
push ax
mov ah,9h
int 21h
call tap
pop ax
ret
outstr endp
;程序功能:菜单信息
;入口参数:无
;出口参数:无
menu proc
push dx
lea dx,str0
call outstr
lea dx,str1
call outstr
lea dx,str3
call outstr
lea dx,str11
call outstr
lea dx,str12
call outstr
lea dx,str13
call outstr
lea dx,str14
call outstr
lea dx,str4
call outstr
xor al,al
call choice
pop dx
ret
menu endp
;程序功能:创建文件
;入口参数:无
;出口参数:无
choice proc
push ax
mov ah,01h
int 21h
call tap
.if al=='1' ;add
call copy
.elseif al=='2' ;show
call show
.elseif al=='3'
call delete
.elseif al=='4'
call copy
.elseif al=='5'
call find
.elseif al=='6' ;exit
jmp over1
.endif
call menu
over1:
pop ax
ret
choice endp
;程序功能:创建文件
;入口参数:无
;出口参数:无
creatfile proc
@@:
lea dx,str5
mov ah,9h
int 21h
lea dx,file_path
mov ah,0ah
int 21h
call tap
mov bl,file_path+1
cmp bl,0
jz @B
xor bh,bh
mov file_path[bx+2],0
lea dx,file_path+2
mov cx,0
mov ah,3ch
int 21h
mov handle,ax
call close
ret
creatfile endp
;程序功能:open文件
;入口参数:无
;出口参数:无
open proc
push ax
push cx
push dx
mov cx,3
mov ah,3dh
lea dx,file_path+2
int 21h
mov handle,ax
pop dx
pop cx
pop ax
ret
open endp
;程序功能:close文件
;入口参数:无
;出口参数:无
close proc
mov bx,handle
mov ah,3eh
int 21h
ret
close endp
;程序功能:read文件
;入口参数:cx,person
;出口参数:无
read proc
push ax
push bx
push cx
push dx
call open
mov ax,count
mov bx,12
mul bx
mov cx,ax
mov bx,handle
lea dx,person
mov ah,3fh
int 21h
call close
pop dx
pop cx
pop bx
pop ax
ret
read endp
;程序功能:write文件
;入口参数:cx,person
;出口参数:无
write proc
push ax
push bx
push cx
push dx
call open
mov ax,count
mov bx,12
mul bx
mov cx,ax
mov bx,handle
lea dx,person
mov ah,40h
int 21h
call close
pop dx
pop cx
pop bx
pop ax
ret
write endp
.startup
call creatfile
call menu
.exit
end


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: