汇编编程实例;;;;统计学生成绩
汇编编程实例;;;;统计学生成绩统计30个学生成绩中得分在100~90、89~80、79~70、69~60区间以及低于60分的人数,并计算30个学生的平均成绩(取整数),结果依次存入指定的存入区域。
例如:
内存中有10个分数 5EH,50H,64H,52H,55H,48H,3AH,4AH,40H,42H
结果为 02H,03H,02H,02H,01H,4DH(平均成绩)
部分程序已经给出,其中原始数据由过程LOAD从文件INPUT1.DAT中读入SOURCE开始的内存单元中,运算结果要 求从RESULT开始存放,由过程SAVE保存到文件OUTPUT1.DAT中。-S
;-----------------xscj.asm------------------------;;
DATA SEGMENT
SCORE DB 78,64,29,91,84,67,92,100,54,66
COUNT EQU 10
RESULT DB 6 DUP (?)
DATA ENDS
;------------------
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
PUSH DS
XOR AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
START: MOV CX,COUNT
MOV AH,0
MOV BX,0
MOV DX,0
MOV SI,OFFSET SCORE
LOP: MOV AL,
CMP AL,60
JB FAIL
CMP AL,70
JB CHA
CMP AL,80
JB ZHONG
CMP AL,90
JB LIANG
YOU: INC AH ;优秀(90-100)
JMP DONE
LIANG: INC BH ;良好(80-89)
JMP DONE
ZHONG: INC BL ;中(70-79)
JMP DONE
CHA: INC DH ;差(60-69)
JMP DONE
FAIL: INC DL ;不及格(59-0)
DONE: INC SI
LOOP LOP
MOV DI,OFFSET RESULT
MOV ,AH
MOV ,BH
MOV ,BL
MOV ,DH
MOV ,DL
MOV CX,COUNT ;求平均
MOV DX,0
MOV SI,OFFSET SCORE
LOP1: MOV AL,
MOV AH,0
ADD DX,AX
INC SI
LOOP LOP1
MOV AX,DX
MOV BL,COUNT
DIV BL
MOV DI,OFFSET RESULT
MOV ,AL
RET
MAIN ENDP
CODE ENDS
END MAIN
从键盘上输入一串字符,计算每个字符出现的次数,并在屏幕上显示这个数字
;count.asmDATA SEGMENT
BUFFER DB 100
DB ?
DB 100 DUP(?)
CHARS DB 'INPUT:$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
PUSH DS
SUB AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
START: MOV DX,OFFSET CHARS
MOV AH,9
INT 21H
MOV DX,OFFSET BUFFER
MOV AH,0AH
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
MOV SI,OFFSET BUFFER
INC SI
MOV AL,
INC SI
MOV DL,
MOV DH,
MOV DI,SI
MOV CL,AL
MOV CH,0
MOV BL,1
MOV BH,0
DEC CL
GO1: INC SI
CMP DL,
JNE TO1
INC BL
TO1: LOOP GO1
CALL OUTPUT
MOV BL,1
TO5: INC DI
DEC AL
CMP AL,1
JE TO3
CMP DH,
JE TO5
MOV DL,
MOV SI,DI
MOV CL,AL
MOV CH,0
DEC CL
GO2: INC SI
CMP ,DL
JNE TO2
INC BL
MOV ,DH
TO2: LOOP GO2
CALL OUTPUT
MOV BL,1
JMP TO5
TO3: CMP DH,
JE TO4
MOV DL,
MOV BL,1
CALL OUTPUT
TO4: RET
MAIN ENDP
;--------------------------
OUTPUT PROC
PUSH AX
PUSH CX
PUSHF
MOV AH,2
INT 21H
MOV DL,20H
MOV AH,2
INT 21H
MOV AL,BL
MOV AH,0
MOV CL,10
DIV CL
ADD AH,30H
ADD AL,30H
MOV CH,AH
MOV DL,AL
MOV AH,2
INT 21H
MOV DL,CH
MOV AH,2
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
POPF
POP CX
POP AX
RET
OUTPUT ENDP
CODE ENDS
END MAIN
从键盘上获得若干个十进制数,求他们的平均值,并输出到屏幕上 。
DATA SEGMENTINPUT DB 4
DB ?
DB 4 DUP (?)
DB '$'
NUM DW 20 DUP(?)
AVE DB ?
OUTPUT1 DB 'INPUT A NUMBER',0DH,0AH,'$'
OUTPUT2 DB 'INPUT AGAIN(END WITH #)',0DH,0AH,'$'
OUTPUT3 DB 'AVERAGE IS:','$'
DATA ENDS
;----------------
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC FAR
PUSH DS
XOR AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
START:MOV DX,OFFSET OUTPUT1
MOV AH,9
INT 21H
MOV BL, 0
MOV DI,OFFSET NUM
MOV DX,OFFSET INPUT
MOV AH,0AH
INT 21H
MOV DX,OFFSET INPUT+2
MOV AH,9
INT 21H
MOV SI,OFFSET INPUT+1
MOV CL,
INC SI
MOV CH,0
CALL ADECXB
MOV ,AX
INC BL
INC DI
INC DI
INN: MOV DX,OFFSET OUTPUT2
MOV AH,9
INT 21H
MOV DX,OFFSET INPUT
MOV AH,0AH
INT 21H
MOV SI,OFFSET INPUT+1
MOV CL,
INC SI
CMP BYTE PTR ,'#'
JZ DONE
MOV CH, 0
CALL ADECXB
MOV ,AX
INC BL
INC DI
INC DI
JMP INN
DONE: MOV DX, 0
PUSH BX
MOV DI,OFFSET NUM
R: MOV AX,
ADD DX,AX
INC DI
INC DI
DEC BL
CMP BL,0
JNZ R
MOV AX,DX
MOV DX,OFFSET OUTPUT3
PUSH AX
MOV AH,9
INT 21H
POP AX
POP BX
DIV BL
MOV AH,0
MOV BL,100
DIV BL
MOV BH,AL
ADD BH,30H
MOV DL,BH
PUSH AX
MOV AH,2
INT 21H
POP AX
MOV AL,AH
MOV AH,0
MOV BL,10
DIV BL
ADD AL,30H
MOV DL,AL
PUSH AX
MOV AH,2
INT 21H
POP AX
ADD AH,30H
MOV DL,AH
MOV AH,2
INT 21H
RET
MAIN ENDP
;-------------
ADECXB PROC
PUSH BX
PUSH CX
PUSH DX
PUSH SI
MOV BH,0
XOR AX,AX
AGAIN:ADD AX,AX
MOV DX,AX
ADD AX,AX
ADD AX,AX
ADD AX,DX
MOV BL,
AND BL,0FH
ADD AX,BX
INC SI
LOOP AGAIN
POP SI
POP DX
POP CX
POP BX
RET
ADECXB ENDP
CODE ENDS
END MAIN
16位无符号数排序
DATA SEGMENTARRAY DW 67 ,32,2,11,501
COUNT EQU $ -ARRAY
WORK DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
STR PROC FAR
PUSH DS
SUB AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
MOV BL,0FFH
ABC: CMP BL,0
JE LAST
XOR BL,BL
MOV SI,COUNT-2
MOV AX,SI
MOV DL, 2
DIV DL
MOV AH,0
MOV CX,AX
ABD: MOV AX,ARRAY
CMP AX,ARRAY
JBE DONE
XCHG ARRAY,AX
MOV ARRAY,AX
MOV BL,0FFH
DONE: DEC SI
DEC SI
LOOP ABD
JMP ABC
LAST: RET
STR ENDP
CODE ENDS
END STR 支持一下。 学习学习! 贴这么多,也不给一个一个分析分析。
不懂 超级无敌不懂 支持一下。
页:
[1]