汇编:使用结构体完成对学生信息(姓名、学号、成绩)的处理

xiaoxiao2021-02-28  66

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; 题目:显示学生名次表 ;具体要求: 1.输入1是数据录入并输出(包括姓名、学号、成绩) ; 2.输入2是排序后的数据输出(包括姓名、学号、成绩、名次) ; 3.输入3是可以按学号查找某学生,并输出其成绩,选择修改或不改成绩(选做) ; ;子程序及功能介绍: ; 1.inputinformation子程序:学生信息的录入,与displaydatas子程序连用,输出学生基本信息。 ; 2.outputinformation子程序:对学生信息按照score进行排序,与displayrank子程序连用,输出 ; 排序后的学生信息并显示排名ranking。 ; 3.displaydatas子程序:显示学生基本信息:name,number,score。 ; 4.displayrank子程序:显示学生排名:name,number,score,ranking。 ; 5.findinformation子程序:按学号查找某学生,并输出其成绩,可选择修改或不改成绩。 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; include 一套工具.mac ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;结构体class,用于存放学生信息 class struc names db 20 dup (?) number db 20 dup (?) score dw ? class ends ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;定义数据段 data segment mem class <> x dw $ y dw ? z dw ? ;存放学生人数 member class 50 dup(<>) show1 db "============================================================",13,10 db "Options:",13,10 db "1.Input student informations(name,number,score)",13,10 db "2.Output student informations(name,number,score,ranking)",13,10 db "3.Find student informations(number)",13,10 db "============================================================",13,10,"$" details1 db "name(eg:MasterShi):$" details2 db "number(eg:201407014212):$" details3 db "score(0-100):$" details4 db "name number score",13,10,"$" details5 db "name number score ranking",13,10,"$" noinformation db "not information!",13,10,"$" information db "score:$" modification db "amend it?(y\n)$" nobody db "nobody!",13,10,"$" blank db " $" blank1 db " $" blank2 db " $" error1 db "Input error,please input again:$" scoreerror db "The score must be 0~100..$" nameerror db "name must be A~Z or a~z..$" numbererror db "number must made by 0~9..$" temp1 db 20 dup (?) temp2 db 20 dup (?) count dw ? result dw ? wc dw ? ranks db ? data ends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;定义堆栈段 stack segment stack ends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;定义附加段 extra segment extra ends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;代码段 code segment assume cs:code,ds:data,ss:stack,es:extra start: mov ax,data mov ds,ax ;加载数据段 ;mov ax,extra mov es,ax ;加载附加段 mov ax,stack mov ss,ax ;加载堆栈段 lea ax,mem sub x,ax set0: oustring show1 set1: input ;输入选项 cmp al,1bh jz exit ;esc键退出 cmp al,31h jz option1 cmp al,32h jz option2 cmp al,33h jz option3 jmp error ;输入的不是1-3 option1: call inputinformation ld jmp set0 option2: call outputinformation ld jmp set0 option3: call findinformation ld jmp set0 error: ld oustring error1 jmp set1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;inputinformation子程序:数据录入并输出;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; inputinformation proc ld out0: ;name mov si,0 oustring details1 set11: input cmp al,13 ;输入的字符是回车 jz out1 cmp al,7ah jg errorname ;输入的字符大于'z' cmp al,61h jge circulationname ;输入的字符在'a'~'z'之间 cmp al,5ah jg errorname ;输入的字符在'Z'~'a'之间 cmp al,41h jge circulationname ;输入的字符在'A'~'Z'之间 jmp errorname ;输入的是其他字符 out1: ;number ld mov si,0 oustring details2 set2: input cmp al,13 jz out2 ;输入回车跳到out2 cmp al,30h jl errornumber cmp al,39h jg errornumber ;输入的字符在0-9之间 mov bx,y mov member[bx].number[si],al inc si jmp set2 out2: ;score ld mov si,0 mov bx,0 oustring details3 set3: input cmp al,13 jz out3 ;输入回车跳到out3 cmp al,30h jl errorscore cmp al,39h jg errorscore ;输入的字符在0-9之间 sub al,30h cbw xchg ax,bx mov cl,10 imul cl add bx,ax jmp set3 out3: cmp bx,100 jg errorscore mov ax,bx mov bx,y mov member[bx].score,ax mov ax,x add y,ax inc z call displaydatas ret circulationname: mov bx,y mov member[bx].names[si],al ;把录入的姓名的字母存入member.name中 inc si jmp set11 errorname: ld oustring nameerror ld cc1: dec si cmp si,0 jl out0 mov bx,y mov member[bx].names[si],0 jmp cc1 errornumber: ld oustring numbererror ld cc2: dec si cmp si,0 jl out1 mov bx,y mov member[bx].number[si],0 jmp cc2 errorscore: ld oustring scoreerror ld mov bx,y mov member[bx].score,0 jmp out2 inputinformation endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;outputinformation子程序:排序后的数据输出;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; outputinformation proc ld cmp z,0 jz nobodys ;比较思路,外层循环控制比较次数,内层循环控制被比较的元素 mov cx,z ;人数,行数,也是控制被比较次数的关键数 dec cx ;n个人比较n-1次 mov wc,cx ;外循环 ccompare: mov cx,wc mov result,cx ;内循环 mov bx,0 compare: mov ax,member[bx].score add bx,x cmp ax,member[bx].score ;两个score比较 jl exchange ;如果前面比后面小,交换 dec result cmp result,0 jg compare dec wc cmp wc,0 jg ccompare jmp out5 exchange: mov dx,member[bx].score sub bx,x mov member[bx].score,dx ;把后面大的数给前面 add bx,x mov member[bx].score,ax ;把前面小的数给后面 ;names lea si,member[bx].names lea di,temp1 mov cx,20 rep movsb ;把后面的串送给temp1 sub bx,x lea si,member[bx].names lea di,temp2 mov cx,20 rep movsb ;把前面的串送给temp2 lea si,temp1 lea di,member[bx].names mov cx,20 rep movsb ;把temp1送给前面的串 add bx,x lea si,temp2 lea di,member[bx].names mov cx,20 rep movsb ;把temp2送给后面的串 ;number lea si,member[bx].number lea di,temp1 mov cx,20 rep movsb ;把后面的串送给temp1 sub bx,x lea si,member[bx].number lea di,temp2 mov cx,20 rep movsb ;把前面的串送给temp2 lea si,temp1 lea di,member[bx].number mov cx,20 rep movsb ;把temp1送给前面的串 add bx,x lea si,temp2 lea di,member[bx].number mov cx,20 rep movsb ;把temp2送给后面的串 dec result cmp result,0 jg compare dec wc cmp wc,0 jg ccompare jmp out5 nobodys: oustring nobody ret out5: call displayrank ret outputinformation endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; displaydatas proc ld oustring details4 mov cx,z ;行数 mov count,cx mov bx,0 ccc: mov member[bx].names[16],'$' oustring member[bx].names ;bx单元中的names显示完毕 mov member[bx].number[16],'$' oustring member[bx].number ;bx单元中的number显示完毕 cmp member[bx].score,10 jge abten mov dx,member[bx].score add dl,30h output dl jmp ddd abten: cmp member[bx].score,100 je hundred mov ax,member[bx].score mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl jmp ddd hundred: mov ax,member[bx].score mov cl,100 idiv cl mov cl,ah add al,30h output al mov al,cl cbw mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl ddd: ld add bx,x dec count cmp count,0 jg ccc ret displaydatas endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; displayrank proc ld oustring details5 mov cx,z ;行数 mov count,cx mov bx,0 ccc: mov member[bx].names[16],'$' oustring member[bx].names ;bx单元中的names显示完毕 mov member[bx].number[16],'$' oustring member[bx].number ;bx单元中的number显示完毕 cmp member[bx].score,10 jge abten mov dx,member[bx].score add dl,30h output dl jmp ddd abten: cmp member[bx].score,100 je hundred mov ax,member[bx].score mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl jmp ddd hundred: mov ax,member[bx].score mov cl,100 idiv cl mov cl,ah add al,30h output al mov al,cl cbw mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl ddd: ;score显示完毕,准备显示ranking inc ranks cmp member[bx].score,100 jz bbb1 cmp member[bx].score,10 jl bbb2 oustring blank jmp xxx bbb1: oustring blank1 jmp xxx bbb2: oustring blank2 xxx: mov dl,ranks add dl,30h output dl ld add bx,x dec count cmp count,0 jg ccc mov ranks,0 ret displayrank endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;findinformation子程序:按学号查找某学生;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; findinformation proc out1: ;number ld cmp z,0 jz nobodys mov si,0 mov cx,20 set3: mov temp1[si],0 inc si loop set3 mov si,0 oustring details2 set2: input cmp al,13 ;输入回车跳到out2 jz out2 cmp al,30h jl errornumber cmp al,39h jg errornumber ;输入的字符在0-9之间,则存入temp1中 mov temp1[si],al inc si jmp set2 out2: mov cx,z mov count,cx ;学生人数 mov bx,0 mov cx,17 rets: lea si,member[bx].number lea di,temp1 repz cmpsb cmp cx,0 jz haveinformation dec count cmp count,0 jz out3 add bx,x mov cx,17 jmp rets out3: ld oustring noinformation ld ret haveinformation: mov result,bx ;先将bx存起来 ld oustring information cmp member[bx].score,10 jge abten mov dx,member[bx].score add dl,30h output dl jmp ddd abten: cmp member[bx].score,100 je hundred mov ax,member[bx].score mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl jmp ddd hundred: mov ax,member[bx].score mov cl,100 idiv cl mov cl,ah add al,30h output al mov al,cl cbw mov cl,10 idiv cl mov cl,ah add al,30h output al add cl,30h output cl ddd: ld oustring modification ret2: input cmp al,'y' jz yes1 cmp al,'Y' jz yes1 cmp al,'n' jz no1 cmp al,'N' jz no1 ld oustring error1 jmp ret2 yes1: ld oustring details3 mov si,0 mov bx,0 set4: input cmp al,13 jz out4 ;输入回车跳到out4 cmp al,30h jl errorscore cmp al,39h jg errorscore ;输入的字符在0-9之间 sub al,30h cbw xchg ax,bx mov cl,10 imul cl add bx,ax jmp set4 out4: cmp bx,100 jg errorscore mov ax,bx mov bx,result mov member[bx].score,ax call displaydatas ret nobodys: oustring nobody ret errorscore: ld oustring scoreerror ld mov bx,y mov member[bx].score,0 jmp yes1 no1: call displaydatas ret errornumber: ld oustring numbererror ld cc2: dec si cmp si,0 jl out1 mov temp1[si],0 jmp cc2 findinformation endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exit: mov ah,4ch int 21h code ends end start

运行结果如下:

1.边界判断

2.录入学生信息

3.按照成绩进行排序

4.按学号查找并修改指定学生成绩(并且名次发生变化,按2可以看到)

转载请注明原文地址: https://www.6miu.com/read-2622112.html

最新回复(0)