DATA SEGMENT
STUDENT STRUCT
XNAME DB 14 DUP('$')
XCLASS DB 14 DUP('$')
NUM DW 0
SCORE DW 0
STUDENT ENDS
STU_SIZE EQU 26
STU_DB STUDENT 100 DUP(<'X','Y',1,100>)
STU_NUM DB 0 ;
STU_SEQ DB 100 DUP('$') ;
MASSAGE DB 'Student Management System',0dh,0ah
DB '0.Exit',0dh,0ah
DB '1.Add New Student',0dh,0ah
DB '2.Sort by Number',0dh,0ah
DB '3.Sort by Score',0dh,0ah
DB '4.Print Average',0dh,0ah
DB '5.Print Statistic',0dh,0ah
DB '$'
MSG1 DB 'Name:','$'
MSG2 DB 'Class:','$'
MSG3 DB 'Number','$'
MSG4 DB 'Score','$'
m_str_l DB 0dh,0ah,'[length<14byte]','$'
m_num_l DB 0dh,0ah,'[value<100]','$'
TABLE DW CASE0,CASE1,CASE2,CASE3,CASE4
BUFLEN DB 100 ;
ACLEN DB ? ;
BUF DB 100 DUP(0),'$' ;
BUFEND EQU OFFSET BUF+100 ;
N_6 DB 0
N67 DB 0
N78 DB 0
N89 DB 0
N9_ DB 0
M_6 DB '~60','$'
M67 DB '60~70:','$'
M78 DB '70~80:','$'
M89 DB '80~90:','$'
M9_ DB '90~100:','$'
DATA ENDS
STACK SEGMENT STACK
DB 200H DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:
PS MACRO STR ;
PUSH AX
PUSH DX
LEA DX,STR
MOV AH,9
INT 21H
POP DX
POP AX
ENDM
PC MACRO CH ;
PUSH AX
PUSH DX
MOV DL,CH
MOV AH,2
INT 21H
POP DX
POP AX
ENDM
ENDL MACRO ;
PC 0DH
PC 0AH
ENDM
SCS MACRO
LEA DX,BUFLEN
MOV AH,10 ;
INT 21H
ENDM
SCC MACRO
MOV AH,1
INT 21H
ENDM
MEMCPY MACRO DEST,SRC,LEN
PUSH AX
PUSH CX
PUSH DI
PUSH SI
MOV AX,DS
MOV ES,AX
MOV CX,WORD PTR LEN
LEA SI,SRC
LEA DI,DEST
CLD
REP MOVSB
POP SI
POP DI
POP CX
POP AX
ENDM
GET_STU MACRO
PUSH AX
PUSH CX
LEA BX,STU_DB
MOV CL,5
SHL AX,CL
ADD BX,AX
POP CX
POP AX
ENDM
MOV AX,DATA
MOV DS,AX
MASSAG: ENDL
PS MASSAGE
PC ':'
SCC
ENDL
MOV AH,0
MOV BX,AX
SUB BX,'0'
CMP BX,5
JBE CASE0TO5
JMP MASSAG
CASE0TO5:
SHL BX,1
JMP TABLE[BX]
CASE0:
MOV AH,4CH
INT 21H
CASE1:
CALL INS_STU
JMP MASSAG
CASE2:
CALL NUM_SORT
CALL PRINT_SEQ
JMP MASSAG
CASE3:
CALL SCORE_SORT
CALL PRINT_SEQ
JMP MASSAG
CASE4:
CALL GET_SAT
JMP MASSAG
INS_STU PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AX,WORD PTR STU_NUM
LEA BX,STU_DB
MOV CL,5
SHL AX,CL
ADD BX,AX
INPUT_NAME:
PS m_str_l
PS MSG1
SCS
CMP ACLEN,14
JAE INPUT_NAME
MEMCPY [BX].XNAME,BUF,ACLEN
ENDL
INPUT_CLASS:
PS m_str_l
PS MSG2
SCS
CMP ACLEN,14
JAE INPUT_CLASS
MEMCPY [BX].XCLASS,BUF,ACLEN
ENDL
INPUT_NUM:
PS m_str_l
PS MSG3
SCS
CALL STR_TO_NUM
MOV [BX].NUM,AX
ENDL
INPUT_SCORE:
PS m_str_l
PS MSG4
SCS
CALL STR_TO_NUM
MOV [BX].SOCRE,AX
ENDL
INC STU_NUM
POP DX
POP CX
POP BX
POP AX
RET
INS_STU ENDP
PNUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,BUFEND
DEC BX
MOV WORD PTR [BX],'$'
OUTLOOP:
OR AX,AX
JZ OUTLOOPFIN
MOV DX,0
MOV CX,10
DIV CX
ADD DL,'0'
DEC BX
MOV BYTE PTR [BX],DL
JMP OUTLOOP
OUTLOOPFIN:
CMP BX,OFFSET BUFEND-1
JNE PRINT_NUM
DEC BX
MOV BYTE PTR [BX],'0'
PRINT_NUM:
MOV DX,BX
MOV AH,9
INT 21H
POP DX
POP CX
POP BX
POP AX
RET
PNUM ENDP
PSCORE PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,BUFEND
DEC BX
MOV BYTE PTR [BX],'$'
OUTLOOP1:
OR AX,AX
JZ OUTLOOP1FIN
MOV DX,0
MOV CX,10
DIV CX
ADD DL,'0'
DEC BX
MOV BYTE PTR [BX],DL
JMP OUTLOOP1
OUTLOOP1FIN:
CMP BX,OFFSET BUFEND-1
JNE PRINT_SCORE
DEC BX
MOV BYTE PTR [BX],'0'
PRINT_SCORE:
MOV DX,BX
MOV AH,9
INT 21H
POP DX
POP CX
POP BX
POP AX
RET
PSCORE ENDP
PSTU PROC NEAR
PUSH AX
PUSH BX
PUSH CX
GET_STU
PS MSG1
PS [BX].XNAME
PC ' '
PS MSG2
PS [BX].CLASS
PC ' '
PS MSG3
MOV AX,[BX].NUM
CALL PNUM
PC ' '
PS MSG4
MOV AX,[BX].SCORE
CALL PSCORE
ENDL
POP CX
POP BX
POP AX
RET
PSTU ENDP
STR_TO_NUM PROC FAR
PUSH BX
PUSH CX
PUSH SI
MOV AX,0
MOV CX,WORD PTR ACLEN
LEA SI,BUF
GET_NUM:
MOV BL,10
MUL BL
MOV BX,WORD PTR [SI]
ADD AX,BX
SUB AX,'0'
INC SI
LOOP GET_NUM
POP SI
POP CX
POP BX
RET
STR_TO_NUM ENDP
GET_AVERAGE PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,0
MOV AX,0
MOV DX,0
REPEATR:
CMP CL,STU_NUM
JAE OUT_PUT
PUSH AX
PUSH CX
MOV AX,CX
GET_STU
POP CX
POP AX
ADD AX,[BX].SOCRE
ADC DX,0
INC CL
JMP REPEATR
OUT_PUT:
MOV CL,STU_NUM
MOV CH,0
OR CL,0
JNZ END_AVE
INC CX
END_AVE:
DIV CX ;
ENDL
CALL PSCORE
ENDL
POP DX
POP CX
POP BX
POP AX
RET
GET_AVERAGE ENDP
GET_SAT PROC NEAR
PUSH AX
PUSH BX
PUSH CX
MOV N_6,0
MOV N67,0
MOV N78,0
MOV N89,0
MOV N9_,0
MOV CX,0
SAT_IN:
CMP CL,STU_NUM
JAE SAT_OUT
PUSH AX
PUSH CX
MOV AX,CX
GET_STU
POP CX
POP AX
INC CL
MOV AX,[BX].SOCRE
CMP AX,60
JB I_6
CMP AX,70
JB I67
CMP AX,80
JB I78
CMP AX,90
JB I89
INC N9_
JMP SAT_IN
I_6:
INC N_6
JMP SAT_IN
I67:
INC N67
JMP SAT_IN
I78:
INC N78
JMP SAT_IN
I89:
INC N89
JMP SAT_IN
SAT_OUT:
MOV AH,0
PS M_6
MOV AL,N_6
CALL PNUM
ENDL
PS M67
MOV AL,N67
CALL PNUM
ENDL
PS M78
MOV AL,N78
CALL PNUM
ENDL
PS M89
MOV AL,N89
CALL PNUM
ENDL
PS M9_
MOV AL,N9_
CALL PNUM
ENDL
POP CX
POP BX
POP AX
RET
GET_SAT ENDP
PRINT_SEQ PROC NEAR
PUSH AX
PUSH BX
LEA BX,STU_SEQ
PRINT_SEQ_START:
MOV AL,[BX]
CMP AL,'$'
JZ PRINT_SEQ_END
MOV AH,0
CALL PSTU
INC BX
JMP PRINT_SEQ_START
PRINT_SEQ_END:
POP BX
POP AX
RET
PRINT_SEQ ENDP
NUM_SORT PROC NEAR
PUSH BX
PUSH DX
MOV DL,0
LEA BX,STU_SEQ
SORT_START:
CMP DL,STU_NUM
JAE SORT_END
MOV BYTE PTR [BX],DL
INC BX
INC DL
JMP SORT_START
SORT_END:
MOV BYTE PTR [BX],'$'
CMP STU_NUM,1
JLE NON_NUM
MOV CL,STU_NUM
DEC CL
MOV CH,0
LOOP1:
MOV DI,CX
LEA BX,STU_SEQ
LOOP2:
MOV AL,BYTE PTR [BX]
MOV AH,0
PUSH BX
GET_STU
MOV DX,[BX].NUM
POP BX
MOV AL,BYTE PTR [BX+1]
PUSH BX
GET_STU
CMP DX,BX.[NUM]
POP BX
JAE CONTI
MOV AL,BYTE PTR [BX]
XCHG AL,BYTE PTR [BX+1]
MOV BYTE PTR [BX],AL
CONTI:
INC BX
LOOP LOOP2
MOV CX,DI
LOOP LOOP1
NON_NUM:
POP DX
POP BX
RET
NUM_SORT ENDP
SCORE_SORT PROC NEAR
PUSH BX
PUSH DX
MOV DL,0
LEA BX,STU_SEQ
SCORE_START:
CMP DL,STU_NUM
JAE SCORE_END
MOV BYTE PTR [BX],DL
INC BX
INC DL
JMP SCORE_START
SCORE_END:
MOV BYTE PTR [BX],'$'
CMP STU_NUM,1
JLE SNON_NUM
MOV CL,STU_NUM
DEC CL
MOV CH,0
SLOOP1:
MOV DI,CX
LEA BX,STU_SEQ
SLOOP2:
MOV AL,BYTE PTR [BX]
MOV AH,0
PUSH BX
GET_STU
MOV DX,[BX].SCORE
POP BX
MOV AL,BYTE PTR [BX+1]
PUSH BX
GET_STU
CMP DX,BX.[SCORE]
POP BX
JAE SCONTI
MOV AL,BYTE PTR [BX]
XCHG AL,BYTE PTR [BX+1]
MOV BYTE PTR [BX],AL
SCONTI:
INC BX
LOOP SLOOP2
MOV CX,DI
LOOP SLOOP1
SNON_NUM:
POP DX
POP BX
RET
SCORE_SORT ENDP
CODE ENDS
END START
程序在RADASM和MASMPLUS上跑出来的反馈的错误都是一样的:
E:\MASM5\huibian.asm(179) : error A2006: undefined symbol : XNAME
MEMCPY(9): Macro Called From
E:\MASM5\huibian.asm(179): Main Line Code
E:\MASM5\huibian.asm(188) : error A2006: undefined symbol : XCLASS
MEMCPY(9): Macro Called From
E:\MASM5\huibian.asm(188): Main Line Code
E:\MASM5\huibian.asm(196) : error A2006: undefined symbol : NUM
E:\MASM5\huibian.asm(204) : error A2006: undefined symbol : SOCRE
E:\MASM5\huibian.asm(300) : error A2006: undefined symbol : XNAME
PS(3): Macro Called From
E:\MASM5\huibian.asm(300): Main Line Code
E:\MASM5\huibian.asm(303) : error A2006: undefined symbol : CLASS
PS(3): Macro Called From
E:\MASM5\huibian.asm(303): Main Line Code
E:\MASM5\huibian.asm(306) : error A2006: undefined symbol : NUM
E:\MASM5\huibian.asm(310) : error A2006: undefined symbol : SCORE
E:\MASM5\huibian.asm(362) : error A2006: undefined symbol : SOCRE
E:\MASM5\huibian.asm(410) : error A2006: undefined symbol : SOCRE
E:\MASM5\huibian.asm(527) : error A2006: undefined symbol : NUM
E:\MASM5\huibian.asm(533) : error A2006: undefined symbol : NUM
E:\MASM5\huibian.asm(588) : error A2006: undefined symbol : SCORE
E:\MASM5\huibian.asm(594) : error A2006: undefined symbol : SCORE
E:\MASM5\huibian.asm(120) : error A2004: symbol type conflict
E:\MASM5\huibian.asm(615) : warning A4023: with /coff switch, leading underscore required for start address : START
构建时发生错误.
总共编译时间 874 毫秒
改来改去发现无从下手,如果要放弃结构体的话应该也是可以写的,但是觉得改起来太麻烦了,不知道诸位有没有办法。。。。