学生成绩管理系统-汇编语言(共19页).docx
精选优质文档-倾情为你奉上;=学生成绩管理系统=;*;EQU STATEMENTS GO HEREStructNodeequ32 ;表达式赋值微操作equ page133Node_nameequ0;类似defineNode_numequ12Node_mathsequ18Node_englishequ20Node_chineseequ22Node_othersequ24Node_totalequ26Node_avgequ28Node_nextequ30max_recordequ100max_menu_indexequ9;*;*data_seg segment;define data segment;DATA GOES HEREbuf1DB30buf1_slenDB?buf1_dataDB30 dup(?)bufnameDB20bufname_slenDB?bufname_dataDB20 dup(?)bufgetintDB32bufgetint_slenDB?bufgetint_dataDB32 dup(?)str_menuDB0dH, 0aH, '=Student marks system=', 0dH, 0aH, 0dH, 0aHDB'1)Add Record', 0dH, 0aH, 0dH, 0aHDB'2)Print All', 0dH, 0aH, 0dH, 0aHDB'3)Save', 0dH, 0aH, 0dH, 0aHDB'4)Open', 0dH, 0aH, 0dH, 0aH, 0dH, 0aHDB'5)Find', 0dH, 0aH, 0dH, 0aH, 0dH, 0aHDB'6)Delete', 0dH, 0aH, 0dH, 0aH, 0dH, 0aHDB'0)Exit', 0dH, 0aHDB'Choice:$'Error Stringsstr_error_1DB'Error input!', 0dH, 0aH, '$'jump_tbDWcase_0DWcase_1DWcase_2DWcase_3DWcase_4DWcase_5DWcase_6headDW?;表头指针info_0db'input num:', '$'info_1db'input math:', '$'info_2db'input english:', '$'info_3db'input chinese:', '$' info_4db'input others:', '$'info_5db'input name:', '$'str_tb_headdb'Num', 9,'Name', 9, 'Maths', 9, 'English', 9, 'Chinese', 9,'Others', 9, 'Total', 9, 'Avg', 0dH, 0aHdb'=', 0dH, 0aH,'$'str_tabdb9, '$'rdatadb(StructNode * (max_record+1) dup(?);全部结点*(100+1)rdata_pdwrdata;下一个可用结点rcountdw00H;当前已分配的结点数newnodedw?pnodedw?file_namedb'c:student.txt', 00Hfile_error1db'Failed create file.', 0DH, 0AH, '$'file_error2db'Failed write file.', 0DH, 0AH, '$'file_error3db'Failed open the file.', 0DH, 0AH, '$'file_error4db'Failed read file.', 0DH, 0AH, '$'file_info_1db'saving the file.', 0DH, 0AH, '$'file_info_2db'Write to file successfully!', 0DH, 0AH, '$'file_info_3db'opening the file.', 0DH, 0AH, '$'file_info_4db'read the file successfully!', 0DH, 0AH, '$'fp1dw?;文件指针data_seg ends;*;*extdata_seg segment;define extra data segment;EXTRA DATA GOES HEREextdata_seg ends;*;*stack_seg segment stack;define extra data segment;STACK DATA GOES HEREDB100H dup(?)stack_seg ends;*;*program segment;define code segment;*main proc far;main part of programassume cs:program, ds:data_seg, es:extdata_seg, ss:stack_segstart:;set up stack for returnpush dssub ax, axpush ax;set DS register to current data segmentmov ax, data_seg;data_seg segment addrmov ds, ax;into DS registermov ax, extdata_seg;extdata_seg segment addrmov es, ax;into ES registermov ax, stack_seg;stack_seg segment addrmov ss, ax;into SS register;MAIN PART OF PROGRAM GOES HERE;分配链表头结点mov ax, rdata_pmov head, ax;当前头指针就是rdata_padd rdata_p, StructNodemov bx, headmov word ptr bx+Node_next, 00Hlb_print_menu:;打印菜单lea dx, str_menumov ah, 09Hint 21Hcall far ptr getintcmp dx, max_menu_indexja lb_print_menumov di, dxshl di, 1jmp jump_tbdijmp lb_print_menucase_0:;Exitretcase_1:;添加记录call far ptr addrecordjmp lb_print_menucase_2:;打印所有记录call far ptr print_recordjmp lb_print_menucase_3:;保存到文件call far ptr save_recordjmp lb_print_menucase_4:;从文件中读取call far ptr read_recordjmp lb_print_menucase_5:;查找call far ptr find_recordjmp lb_print_menucase_6:;删除call far ptr delete_recordjmp lb_print_menuret;return to DOSmain endp;end of main part of program;*;*sub1 proc near;define subprocedurepush axpush bxpush cxpush dx;main port of sub procedure;exit sub procedurepop dxpop cxpop bxpop axretsub1 endp;end of subprocedure;*;*;print CRLFcrlf proc farpush dxpush axmov dl, 0dHmov ah, 02Hint 21Hmov dl, 0aHmov ah, 02Hint 21hpop axpop dxretcrlf endp;*;*;从键盘输入一个整数,结果保存到dx中getint proc far;define subprocedurepush axpush bxpush cx;main port of sub proceduremov dx, offset bufgetint;offset 偏移地址mov ah, 0aHint 21Hcall far ptr crlfmov ax, offset bufgetint_datapush ax;字符串首地址mov al, bufgetint_slencbw;字节转字push ax;字符串长度push ax;返回值call far ptr decibinpop dxpop axpop ax;exit sub procedurepop cxpop bxpop axretgetint endp;end of subprocedure;*;*;把以十制进数形式存储在字符串中的数转成整数;栈中的参数:;0字符串首地址;1字符串长度;2存放结果decibin_para_lenequ3decibin_str1equword ptrbp+4+(decibin_para_len-0)*2decibin_str1lenequword ptrbp+4+(decibin_para_len-1)*2decibin_retsultequword ptrbp+4+(decibin_para_len-2)*2decibin proc far;save registerspush bpmov bp, sppush axpush bxpush cxpush dxpush sipush dimov bx, 00Hmov cx, decibin_str1lenmov di, decibin_str1decibin_loop1:mov al, byte ptr di ; di为偏移量以字节为单位 把地址送入al and al, 0fHcbwxchg bx, axmov si, 10mul siadd bx, axinc diloop decibin_loop1mov decibin_retsult, bxexit_decibin:;恢复寄存器pop dipop sipop dxpop cxpop bxpop axpop bpretdecibin endp;*;*;把bx中的数以十进制形式输出;输入:数据存放在bx中binidec proc farpush axpush bxpush cxpush dxpush simov si, 01Hmov cx,10000d;各位依次输出call dec_divmov cx,1000dcall dec_divmov cx,100dcall dec_divmov cx,10dcall dec_divmov cx,1dmov si, 00Hcall dec_divpop sipop dxpop cxpop bxpop axretbinidec endpdec_div proc nearmov ax,bxmov dx,0div cxmov bx,dx;保留余数mov dl,al;商送入dlcmp si, 00H;输出这一位je lb1_dec_divcmp dl, 00H;处理完毕je exit_dec_divmov si, 00Hlb1_dec_div:add dl,30hmov ah, 02Hint 21Hexit_dec_div:retdec_div endp ;*;*addrecord proc far;define subprocedurepush axpush bxpush cxpush dxpush sipush dipush es;main port of sub proceduremov ax, rdata_p;当前指针移入axmov newnode, ax;再移入newnode存储单元中add rdata_p, StructNode;相当于指针加一add rcount, 1;计数器加一mov bx, ax;当前指针(newnode所指)移入bxmov cx, 00H ;计算总分mov word ptr bx+Node_next, 00H;Node_next置lea dx, info_0mov ah, 09Hint 21Hcall far ptr getintcall crlfmov word ptr bx+Node_num, dxlea dx, info_1mov ah, 09Hint 21Hcall far ptr getintcall crlfadd cx, dxmov word ptr bx+Node_maths, dxlea dx, info_2mov ah, 09Hint 21Hcall far ptr getintcall crlfadd cx, dxmov word ptr bx+Node_english, dxlea dx, info_3mov ah, 09Hint 21Hcall far ptr getintcall crlfadd cx, dxmov word ptr bx+Node_chinese, dxlea dx, info_4mov ah, 09Hint 21Hcall far ptr getintcall crlfadd cx, dxmov word ptr bx+Node_others, dxmov word ptr bx+Node_total, cx;计算平均成绩mov ax, cxcwdmov cx, 4div cxmov word ptr bx+Node_avg, axlea dx, info_5mov ah, 09Hint 21H;输入姓名lea dx, bufnamemov ah, 0aHint 21Hcall far ptr crlfmov ax, dsmov es, axmov al, bufname_slencbwmov bx, axmov byte ptr bufname_databx, '$'lea si, bufname_datamov di, newnodemov cx, bxinc cxcldrep movsb;add the new node to the listmov di, newnode;newnode现在存放的是当前项的地址mov si, head;head存放的是头指针mov ax, word ptr si+Node_nextmov word ptr di+Node_next, ax;当前加入项指向上次项(head指向的送当前项指针Node_next)mov word ptr si+Node_next, di;头指针指向当前加入项(当前项的地址送head);exit sub procedurepop espop dipop sipop dxpop cxpop bxpop axretaddrecord endp;end of subprocedure;*;*print_record proc far;define subprocedurepush axpush bxpush cxpush dxpush sipush di;main port of sub procedurelea dx, str_tb_headmov ah, 09Hint 21Hmov ax, headmov pnode, axloop1_print_record:mov si, pnodemov ax, si+Node_nextmov pnode, axcmp ax, 00Hje exit_print_record1mov si, pnode;打印学号mov bx, si+Node_numcall far ptr binidec;打印制表符lea dx, str_tabmov ah, 09Hint 21H exit_print_record1: cmp ax,00hje exit_print_record ;非要分次跳跃;打印名字mov dx, simov ah, 09Hint 21H;打印制表符lea dx, str_tabmov ah, 09Hint 21H;数学成绩mov bx, si+Node_mathscall far ptr binidec;打印制表符lea dx, str_tabmov ah, 09Hint 21H;英语成绩mov bx, si+Node_englishcall far ptr binidec;打印制表符lea dx, str_tabmov ah, 09Hint 21H;语文成绩mov bx, si+Node_chinesecall far ptr binidec;打印制表符lea dx, str_tabmov ah, 09Hint 21H;语文成绩mov bx, si+Node_otherscall far ptr binidecloop1_print_record1:cmp ax,0000hje loop1_print_record;打印制表符lea dx, str_tabmov ah, 09Hint 21H;总成绩mov bx, si+Node_totalcall far ptr binidec;打印制表符lea dx, str_tabmov ah, 09Hint 21H;平均成绩mov bx, si+Node_avgcall far ptr binideccall far ptr crlfmov ax,0000hjmp loop1_print_record1exit_print_record:;exit sub procedurepop dipop sipop dxpop cxpop bxpop axretprint_record endp;end of subprocedure;*;*save_record proc far;define subprocedurepush axpush bxpush cxpush dxpush sipush di;main port of sub procedure;Create filelea dx, file_namemov cx, 00Hmov ah, 3cHint 21Hjc save_record_error1mov fp1, ax;write record countmov ah, 40Hmov bx, fp1mov cx, 02Hlea dx, rcountint 21Hjc save_record_error2lea dx, file_info_1mov ah, 09Hint 21Hmov ax, headmov pnode, axloop1_save_record:mov si, pnodemov ax, si+Node_nextmov pnode, axcmp ax, 00Hje save_record_ok;write current node to the filemov ah, 40Hmov bx, fp1mov cx, StructNodemov dx, pnodeint 21Hjc save_record_error2jmp loop1_save_recordsave_record_ok:lea dx, file_info_2mov ah, 09Hint 21Hjmp save_record_close_filesave_record_error1:lea dx, file_error1mov ah, 09Hint 21Hjmp exit_save_recordsave_record_error2:lea dx, file_error2mov ah, 09Hint 21Hjmp exit_save_recordsave_record_close_file:mov ah, 3eHmov bx, fp1int 21Hexit_save_record:;exit sub procedurepop dipop sipop dxpop cxpop bxpop axretsave_record endp;end of subprocedure;*;*read_record proc far;define subprocedurepush axpush bxpush cxpush dxpush sipush di;main port of sub procedure;Open filelea dx, file_namemov ah, 3dHmov al, 00Hint 21Hjc read_record_error1mov fp1, ax;read record countmov ah, 3fHmov bx, fp1mov cx, 02Hlea dx, rcountint 21Hjc read_record_error2lea dx, file_info_3mov ah, 09Hint 21H;分配链表头结点lea ax, rdatamov head, axmov rdata_p, axadd rdata_p, StructNodemov bx, headmov word ptr bx+Node_next, 00Hmov cx, rcountloop1_read_record:push cxmov ax, rdata_pmov newnode, axadd rdata_p, StructNode;read new nodemov ah, 3fHmov bx, fp1mov cx, StructNodemov dx, newnodeint 21Hjc read_record_error2;add new node to listmov di, newnodemov si, headmov ax, word ptr si+Node_nextmov word ptr di+Node_next, axmov word ptr si+Node_next, dipop cxloop loop1_read_recordread_record_ok:lea dx, file_info_4mov ah, 09Hint 21Hjmp read_record_close_fileread_record_error1:lea dx, file_error3mov ah, 09Hint 21Hjmp exit_read_recordread_record_error2:lea dx, file_error4mov ah, 09Hint 21Hjmp exit_read_recordread_record_close_file:mov ah, 3eHmov bx, fp1int 21Hexit_read_record:;exit sub procedurepop dipop sipop dxpop cxpop bxpop axretread_record endp;end of subprocedure;*find_record proc farpush axpush bxpush cxpush dxpush sipush dilea dx, info_0mov ah, 09Hint 21Hcall far ptr getintcall crlfmov si, headmov di, headfind_again: mov di,word ptr di+Node_next