?? test.asm
字號:
;*************************************************************************
;匯編程序_班級04407_學號041165_序號10_陳見雨
; 完成于2006年12月16日
; email: colama_man@qq.com
;
;輸入學生總數:1-99
;輸入格式為:班級-學號-姓名
;如04407-041165-chen 字符個數必須為5-6-姓名(最大為5個字符)
;字符個數即為:班級5個,學號6個,姓名不大于5個字符
;*************************************************************************
data segment
number_tip db 'Please input the number of student(1-99):$'
name_tip db 0dh,0ah,'Please input the information(Class-XueHao-Name):',0dh,0ah,'$'
gradetip db 0dh,0ah,'Please input the grades(qimo qizhong shiyan pingshi):',0dh,0ah,'$'
show_result db 0dh,0ah,'Class-XueHao-Name : ChengJi',0dh,0ah,0dh,0ah,'$'
stars db 0dh,0ah,'************************************','$'
maohao db ' : $'
space db ' $'
fenshuduan db 0dh,0ah,'[Below 60][60-70][70-80][80-90][90-100]',0dh,0ah,'$'
snumber1 db 3 dup(0) ;存儲學生總數(ASCII表示)
snumber2 db 0 ;存儲學生總數(十進制)
student db 1980 dup(0) ;輸入格式為:班級-學號-姓名,最多支持99個人,每個人占用21個空間單元
buffer1 db 8 dup(0) ;為學生成績分配空間(ASCII表示)
buffer2 db 4 dup(0) ;為學生成績分配空間(十進制表示)
resultes db 99 dup(3 dup(0)) ;存儲每個學生平均分,每個人的平均分占用3單元,共99人
n db 5 dup(0) ;存儲60以下、60-70、70-80、80-90、90-100分段內的人數
data ends
;**************************************************************************
code segment
;-----------------------------------------------------------
main proc far
assume cs:code,ds:data
start:
mov ax,data ;數據段初始化
mov ds,ax
mov es,ax
mov si,0 ;指向每個學生姓名
mov di,0 ;指向每個學生總評成績
mov cx,100 ;初始化學生數
;---------------------------------------------------------------------------
lea dx,number_tip ;請求輸入學生總數
mov ah,09
int 21h
call store_number ;存儲學生總數,結果送cx中
cmp cx,0 ;輸入為0退出
jle retdos
cmp cx,100 ;學生數超出本程序范圍,退出
jge retdos
;--------------------------------------------------------------------------------
begin:
lea dx,name_tip ;請求輸入學生信息,格式為:班級-學號-姓名,字符長度必須為5-6-4
mov ah,09
int 21h
call store_name ;存儲學生姓名
add si,20 ;指向下一個學生姓名
lea dx,gradetip ;請求輸入學生成績
mov ah,09
int 21h
call store_grades ;存儲每個學生成績
call compute ;計算每個學生平均分
add di,3 ;分別存儲每個學生的平均分,di指向每個學生平均分
;因為存儲的是3位,di每次加3才能指向下一個學生
loop begin ;循環,直到輸入所有學生成績
call sort ;排序
call display ;顯示結果
;----------------------------------------------------------------------
retdos:
mov ah,1 ;任意鍵結束
int 21h
mov ax,4c00h ;返回DOS
int 21h
;**************************************************************************
; 以下為子程序部分
;**************************************************************************
; 以下為子程序部分
;*************************************************************************
store_number proc
push ax
push bx
mov bx,0
store:
mov ah,01
int 21h ;輸入字符
cmp al,0dh ;判斷是否輸入回車
je cr_ ;輸入結束
and al,0fh ;轉換成非壓縮的BCD碼
mov snumber1[bx],al
inc bx ;輸入未結束,則繼續輸入
jmp store
cr_:
cmp bx,2 ;學生數大于10,還是小于10,最多支持99人
jz llll
jg large ;學生數大于99返回,bx>2
mov al,snumber1 ;輸入學生數小于10,大于0
jmp lllll
llll: mov ah,snumber1
mov al,snumber1+1
aad ;BCD碼轉換為二進制數
lllll: mov snumber2,al
mov cx,0
mov cl,snumber2
large:
pop bx
pop ax
ret
store_number endp
;****************************************************************************
store_name proc
push dx
push ax
push bx
mov al,18 ;每個學生單元最大可存儲字符數,包括回車
mov student[si],al
lea dx,student[si] ;讀取學生姓名
mov ah,0ah
int 21h
mov bl,student[si+1] ;bl存儲實際輸入字符個數,不包括回車
mov al,' ' ;將實際輸入字符最后鍵入的回車換成空格
mov student[si+bx+2],al
mov student[si+19],'$' ;在一個學生存儲單元的最后加上'$',一個學生的輸入結束
;存儲的時候必須加上這個'$'否則打印的時候出錯
pop bx
pop ax
pop dx
ret
store_name endp
;*****************************************************************************
store_grades proc
push ax
push di
mov di,0
input:
mov ah,1
int 21h ;輸入字符
cmp al,0dh ;判斷是否輸入回車
je return ;輸入結束
cmp al,' ' ;判斷是否輸入空格
;************重大失誤?。?!我竟然寫成cmp al,0ah!!!結果使計算結果老是出錯!浪費一個下午!
je input ;跳過空格
and al,0fh ;轉換成非壓縮的BCD碼
mov buffer1[di],al
inc di ;輸入未結束,則繼續輸入
jmp input
return:
pop di
pop ax
ret
store_grades endp
;****************************************************************************
compute proc ;計算平均成績主程序
push ax
push si
push cx
push dx
push bx ;bx用做臨時存儲數據用
mov si,0
mov ax,0
mov dx,0
mov bx,0
;-----------------------------------------------------------------
mov cx,4 ;循環實現BCD碼轉換為二進制數
next1:
mov ah,buffer1[si]
mov al,buffer1[si+1]
aad
mov buffer2[bx],al
add si,2
inc bx
loop next1
;------------------------------------------
;期末成績×0.6+期中成績×0.2+實驗成績*0.1+平時成績*0.1
mov si,0 ;計算平均成績,結果用十進制表示
mov bx,0 ;清零
mov al,6
mul buffer2[si]
add bx,ax
mov al,2
mul buffer2[si+1]
add bx,ax
mov al,1
mul buffer2[si+2]
add bx,ax
mov al,1
mul buffer2[si+3]
add bx,ax
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
增大字號
Ctrl + =
減小字號
Ctrl + -