Chinaunix首页 | 论坛 | 博客
  • 博客访问: 20278
  • 博文数量: 17
  • 博客积分: 730
  • 博客等级: 军士长
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-24 12:09
文章分类

全部博文(17)

文章存档

2010年(17)

我的朋友
最近访客

分类: 嵌入式

2010-01-24 13:39:27


;
; 5、编程,键入某班某课成绩,统计各类成绩的人数。
;
;程序说明:
;按照提示说明,键入一个学生的成绩,然后再根据提示操作即可

DATAS SEGMENT
num_90_100 dw 0
num_80_89 dw 0
num_70_79 dw 0
num_60_69 dw 0
num_0_59 dw 0
print_90_100 db "~~~90 ~100 number is :$"
print_80_89 db  "~~~80 ~ 89 number is : $"
print_70_79 db  "~~~70 ~ 79 number is :$"
print_60_69 db  "~~~60 ~ 69 number is :$"
print_0_59  db "!!!!!!!!!!the number of unpassed student is:$"
quit db "do you want to quit ?y for quit ,any other key for insert!$"
welcome db "what do you want to do?"
db 0ah,0dh
db " input 'i' to insert a score ~!"
db 0ah,0dh
db " input 'p' to print the current student number~!"
db 0ah,0dh
db " any other key for quit~!"
db 0ah,0dh,'$'
inputs db 0ah,0dh
db " please input a number: "
db 0ah,0dh,'$'
DATAS ENDS

STACKS SEGMENT
  
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
;;;;;;;下面的程序是供显示出结果使用的
show_asc proc
push ax
push bx
push cx
push dx
mov bx,dx
mov cx,2
mov ah,02h
lop:
mov dl,bl
int 21h
push cx
mov cl,8
shr bx,cl
pop cx
dec cx
jnz lop
;输出结尾字符h,作为16进制的结尾标志
mov ah,02h
mov dl,'h'
int 21h
pop dx
pop cx
pop bx
pop ax
ret
show_asc endp
;ax = 要输出的数字  dx=格式化的数字
;把一个两位数的每一个ascii打印出来。
show_num proc
push ax
push bx
push cx
push dx
mov cx,2h
mov bx,ax
mov dx,0
lop2:
mov bl,al
and bx,0fh
add bl,30h
cmp bl,'9'
jng next
add bl,7h
next:
or dx,bx
dec cx
jz  ok
push cx
mov cl,4
shl dx,cl
shl dx,cl  ;由于一个字符要占8个bit,所以dx往左移8位
shr ax,cl  ;而ax移动4位
pop cx
jmp lop2
ok:
call show_asc
pop dx
pop cx
pop bx
pop ax
ret
 
show_num endp 

;换行
change_line proc
push ax
push dx
mov ah,2h
mov dl,0ah
    int 21h
    mov dl,0dh
    int 21h
    pop dx
    pop ax
ret
change_line endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
;;从键盘上获得分数,由于分数最多是100分,所以一共也就3位
;;ax 返回的是分数的十进制数值


get_num proc
;如果输入的数字的范围超过了100,提示不合法则重新输入。
push bx
push cx
push dx
get_num_proc_begin:
mov cx,3
mov dx,0
mov bx,10
get_num_lop:
call get_a_num
cmp al,0dh
je get_num_end
push ax
mov ax,dx
mul bl
mov dx,ax
pop ax
add dx,ax
loop get_num_lop
get_num_end:
mov ax,dx
pop dx
pop cx
pop bx
ret
;由于,ax作为返回值使用,所以此处不再保存ax
get_num endp
;;;;;;;;;;;;;;;;;获得一个字符,并把它转化为十进制数,如果不合法
;;提示重新输入一个合法的 如果是回车的话,直接返回0x0d
get_a_num proc
push bx
push cx
push dx
re_get_a_num:
mov ah,01h
int 21h
cmp al,0dh
je get_a_num_end
cmp al,'0'
jb re_get_a_num
cmp al,'9'
jg re_get_a_num
sub al,30h

get_a_num_end:
pop dx
pop cx
pop bx
ret
get_a_num endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;               打印出各层次 的人数。
;

print_num_score proc
push ax
push bx
push cx
push dx
;打印出下列的一系列数字
lea dx, print_90_100
mov ah,9h
int 21h
mov ax,num_90_100
call show_num
call change_line
;80-89
lea dx,print_80_89
mov ah,9h
int 21h
mov ax,num_80_89
call show_num
call change_line
;70-79
lea dx,print_70_79
mov ah,9h
int 21h
mov ax,num_70_79
call show_num
call change_line
;60-69
lea dx,print_60_69
mov ah,9h
int 21h
mov ax,num_60_69
call show_num
call change_line
;unpassed
lea dx,print_0_59
mov ah,9h
int 21h
mov ax,num_0_59
call show_num
call change_line
pop dx
pop cx
pop bx
pop ax
ret
print_num_score endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 把对应分数段的名额增加一个学生
       ;;根据ax的值来判断到底应该增加哪一个分数段的人数

inc_area_num proc
push ax
push bx
push cx
push dx
cmp al,59
jb inc_area_1
cmp al,69
jb inc_area_2
cmp al,79
jb inc_area_3
cmp al,89
jb inc_area_4
jmp inc_area_5
inc_area_1:
mov ax,num_0_59
inc ax
mov num_0_59,ax
jmp inc_area_end
inc_area_2:
mov ax,num_60_69
inc ax
mov num_60_69,ax
jmp inc_area_end
inc_area_3:
mov ax,num_70_79
inc ax
mov num_70_79,ax
jmp inc_area_end
inc_area_4:
mov ax,num_80_89
inc ax
mov num_80_89,ax
jmp inc_area_end

inc_area_5:
mov ax,num_90_100
inc ax
mov num_90_100,ax

inc_area_end:
pop dx
pop cx
pop bx
pop ax
ret
inc_area_num endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
; 打印欢迎和选择信息
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print_welcome proc
push ax
push dx
lea dx,welcome
mov ah,09h
int 21h
pop dx
pop ax
ret
print_welcome endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                  以下是主程序  
;                                
START:
    MOV AX,DATAS
    MOV DS,AX
    
loping:  
call print_welcome
mov ah,01h
int 21h
cmp al,'i'
je insert
cmp al,'I'
je insert
cmp al,'p'
je print
cmp al,'P'
je print
 
mov ah,4ch
int 21h
insert:
lea dx,inputs
mov ah,9h
int 21h
call change_line
call get_num
call change_line
call inc_area_num
jmp loping
print:
call change_line
call print_num_score
call change_line
jmp loping
CODES ENDS
    END START
 


阅读(292) | 评论(0) | 转发(0) |
0

上一篇:无符号数比较

下一篇:统计正数

给主人留下些什么吧!~~