⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grade(9).asm

📁 一个简单的统计成绩的汇编程序。输入一组成绩后对成绩排序
💻 ASM
字号:
;--------------------------------------------------------------------------------

datarea segment
        LEN               dw 1 dup(?)
        MAX_LEN           equ 30
        grade_head        dw MAX_LEN DUP(?)
        grade_end         dw 0
        average           dw 1 dup(?)
        low60             dw 1 dup(?)
        from60to70        dw 1 dup(?)
        from70to80        dw 1 dup(?)
        from80to90        dw 1 dup(?)
        high90            dw  1 dup(?)
datarea ends
;--------------------------------------------------------------------------------
echorea segment
        mess1  db    'please input the total count<30:',13,10,'$'
        mess2  db    'please input each grade:',13,10,'$'
        mess3  db    'now, print all grade:',13,10,'$'
        mess4  db    'now, the highest grade is:',13,10,'$'
        mess5  db    'now, the lowest grade  is:',13,10,'$' 
        mess6  db    'now, the average grade is:',13,10,'$'
        mess7  db    'now, the grade abover then 90:',13,10,'$'
        mess8  db    'now, the grade from 80 to 90:',13,10,'$'
        mess9  db    'now, the grade from 70 to 80:',13,10,'$'
        mess10  db    'now, the grade from 60 to 70:',13,10,'$'
        mess11  db    'now, the grade less than 60 :',13,10,'$'
       
echorea ends
;--------------------------------------------------------------------------------

program segment
      assume cs:program,ds:datarea,es:echorea

main proc far
	
	mov ax,datarea
	mov ds,ax
	
	mov ax,echorea
	mov es,ax
	
	;请输入人数
	lea dx,mess1
	call printfs
	call decInput 
	mov  LEN,bx	
	call crlf 
	
	;请输入成绩	
	lea dx,mess2
	call printfs             
        mov cx,LEN        ;用来输入成绩时循环的次数
	mov si,0          ;初始化指针
 input:	 
          call  decInput
          mov grade_head[si],bx
          add si,2
          call  crlf
          loop input
  
       call sort           ;对成绩进行排序
       ;输出最高成绩       
       lea dx,mess4
       call printfs
       mov bx,grade_head[0]
       call decprint
       call crlf 
       ;输出最低成绩
       lea dx,mess5
       call printfs
       mov si,LEN
       shl si,1
       mov bx,grade_head[si-2]
       call decprint
       call crlf 
       
       ;输出各段成绩和平均成绩
       lea dx,mess6
       call printfs 
       mov bx,average
       call decprint            ; 输出平均成绩
       call crlf 
       
       lea dx,mess11
       call printfs 
       mov bx,low60
       call decprint 
       call crlf
       ;输出成绩 
     
       lea dx,mess3
       call printfs
       mov cx,LEN
       mov si,0 
 print:  
          mov bx,grade_head[si]
          call decprint 
          call crlf 
          add si,2
          loop print
         	
	mov ax,4c00h
	int 21h

main endp

;用来输出字符串 DX用来指向字符串的地址,而DS已经是字符串的段地址了
printfs proc near
	
	push ds
	mov ax,echorea
	mov ds,ax
	mov ah,09h
	int 21h	
	pop ds	
	ret
printfs endp

;用来输入十进制数,并且保存在BX中
decInput  proc near
	
	push cx
	mov bx,0
  newchar:   
              mov ah,1h
              int 21h
              sub al,30h
              jl   exit
              cmp al,9d
              jg   exit
              cbw  
              
              ;现在字符保存在AX中.   
              ;下面把它转化成数字并且保存到BX中                 
              xchg ax,bx       ;交换以便循环利用
              mov  cx,10d
              mul cx
              xchg ax,bx
              
              ;现在已经完成了转化转入BX中
              add bx,ax
              jmp newchar        ;循环输入数字
                                        
  exit:  pop cx	
         ret

decInput endp

;用简单冒泡排序对成绩进行排序
sort proc near
	
	mov cx,LEN
	dec cx
   loop1:    
           mov di,cx
           mov bx,0
           
           loop2:
                     mov ax,grade_head[bx]
                     cmp ax,grade_head[bx+2]
                     jge continue
                     xchg ax,grade_head[bx+2]
                     mov grade_head[bx],ax
                     
           continue: 
                     add bx,2
                     loop loop2
                     mov cx,di
                     loop loop1
	ret

sort endp

;统计各阶段的人数和平均成绩
subsection proc near
	mov si,0                         ;用作指针
	mov dx,0                         ;用来统计总的成绩
	mov cx,LEN
  stat:
            mov ax,grade_head[si]
            cmp ax,90
            jge case1
            cmp ax,80
            jge case2
            cmp ax,70
            jge case3
            cmp ax,60
            jge case4
            jmp case5
            
    case1:  inc high90
    case2:  inc from80to90
    case3:  inc from70to80
    case4:  inc from60to70
    case5:  inc low60
        
        add dx,ax                            ;加入总成绩中
        add si,2                             ;指针下移
        loop   stat
        mov ax,dx
        div LEN
        cbw
	mov average,ax
	ret

subsection endp

;把BX中的两位十进制数输出
decprint proc near
	
	mov ax,bx
	mov bl,10d
	div bl
	mov bl,ah
	add al,30h
	mov dl,al
	mov ah,02h
	int 21h             ;输出十位上的数
	
	add bl,30h
	mov dl,bl
	int 21h             ;输出各位上的数
	
	ret

decprint endp

crlf proc near
        
        mov dl,0dh
        mov ah,2
        int 21h
        mov dl,0ah
        mov ah,2
        int 21h
    	
	ret
	
crlf endp
;--------------------------------------------------------------------------------
program ends
        end main

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -