汇编语言综合题-2
一、题目要求
成绩统计。
输入学生的成绩(百分制,满分100),按Enter后,依次显示:及格人数﹐不及格人数﹐成绩排序结果﹐平均分。
要求:输入和输出都要有必要的提示﹐且提示独占一行﹔输入要有边界判断。
1)输入6个学生成绩﹐之间空格隔开﹐按Enter结束输入﹔2)统计并显示:及格人数x个﹐不及格人数y个;
3)将成绩按从小到大排序﹐并输出﹔
4)计算成绩平均分﹐并输出(结果保留到小数点后1位)。
二、代码实现
DATAS SEGMENT
;此处输入数据段代码
fail DB '0'
pass DB '6'
sum DW 0
num DB 6
xiaoshu DB ?
zhengshu DB ?
org 20h
stu DW 0,0,0,0,0,0
shuru DB 'Please input 6 student scores (full score is 100 points) : $'
failman DB 'The number of people who failed is :$'
passman DB 'The number of people who pass is :$'
average DB 'What is the average score of the students :$'
DATAS ENDS
enterline macro ;宏定义,完成回车换行
mov dl,13;回车
mov ah,2
int 21h
mov dl,10;换行
mov ah,2
int 21h
endm
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
mov dx,offset shuru
mov ah,9
int 21h
enterline
mov si,1
;输入学生成绩
fanhui:
xor bx,bx ;bx清零
input: ;输入字符 转为 数字
mov ah,1H ;在al里面
int 21H
cmp al,13 ;与空格比较如果
JZ next1 ;输入结束
SHL bx,1 ;bx = bx *2
mov cx,bx
SHL cx,1
SHL cx,1 ;cx = bx *2*2*2
add bx,cx ;bx = bx *10 完成bx * 10
XOR cx,cx ;清零cx
mov cl,al
sub cl,30H
add bx,cx ;num存在bx里面
jmp input
next1:
add sum,bx
cmp bx,60 ;bx和60比较
jae next2
inc fail
dec pass
next2:
dec num
mov stu[si],bx ;student从si到si+5
inc si
inc si
cmp num,0;外循环走6级
jne fanhui
;fail
mov dx,offset failman
mov ah,9
int 21h
mov dl,fail
mov ah,2
int 21h
enterline
;pass
mov dx,offset passman
mov ah,9
int 21h
mov dl,pass
mov ah,2
int 21h
;输出sum/6
enterline
mov dx,offset average
mov ah,9
int 21h
xor ax,ax
mov cl,6
mov ax,sum
div cl ;al商ah余数
mov zhengshu,al
mov xiaoshu,ah
xor ax,ax
mov cl,10
mov al,zhengshu
div cl ;al商ah余数
mov cl,ah ;保护余数ah
add al,30h
mov dl,al
mov ah,02h
int 21h ;shiwei
add cl,30h
mov dl,cl
mov ah,02h
int 21h ;gewei
mov dl,2eh ;小数点
mov ah,02h
int 21h
;xiao shu
mov cl,10
mov al,xiaoshu
mul cl ;小数部分乘10
mov cl,6
div cl ;al商ah余数
;25 26 78 98 63 21
add al,30h
mov dl,al
mov ah,02h
int 21h
;从小到大
enterline ;1 3 5 7 9 11
;外循环
mov bx,1
wai:
;把si给bx bx外,si内
mov si,1
nei: ;内循环
mov cx,stu[si+2]
cmp stu[si],cx
jbe next7
xchg stu[si],cx
xchg stu[si+2],cx
next7:
inc si
inc si
mov ax,12
sub ax,bx
;si与11-bx比较
cmp si,ax
jne nei
;wai
inc bx
inc bx
cmp bx,11
jne wai
mov si,1
shuchu:
xor ax,ax
mov bl,10 ;输出
mov ax,stu[si]
div bl ;al商ah余数
mov bl,ah
add al,30h
mov dl,al
mov ah,02h
int 21h
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov dl,' '
mov ah,02h
int 21h
inc si
inc si
cmp si,13
jne shuchu
;此处输入代码段代码
MOV AH,4CH
INT 21H
CODES ENDS
END START