?? huibian1.asm
字號:
;*************************************************************************
data segment
name_tip db 'Please input the student name:$'
gradetip db 0dh,0ah,'Please input the grades:$'
show_result db 0dh,0ah,'Name : ChengJi',0dh,0ah,0dh,0ah,'$'
stars db 0dh,0ah,'************************************','$'
maohao db ' : $'
student db 100,0,100 dup(?) ;學生姓名
buffer1 db 40 dup(0) ;為學生成績分配空間(ASCII表示)
buffer2 db 20 dup(0) ;學生成績(十進制表示)
resultes db 100 dup(0) ;存儲每個學生平均分
data ends
;**************************************************************************
code segment
;-----------------------------------------------------------
main proc far
assume cs:code,ds:data
start:
mov ax,data ;數據段初始化
mov ds,ax
lea dx,name_tip ;請求輸入學生姓名
mov ah,09
int 21h
call store_name ;存儲學生姓名
lea dx,gradetip ;請求輸入學生成績
mov ah,09
int 21h
call store_grade ;存儲學生成績
call compute ;計算平均分
call display ;顯示結果
mov ah,1 ;任意鍵結束
int 21h
mov ax,4c00h ;返回DOS
int 21h
;**************************************************************************
; 以下為子程序部分
;**************************************************************************
; 以下為子程序部分
;****************************************************************************
store_name proc
push dx
push ax
push bx
lea dx,student ;讀取學生姓名
mov ah,0ah
int 21h
mov bl,student+1 ;存放實際的個數
and bx,0fh ;bx高四位清零
mov student[bx+2],'$' ;在最后加上'$'
pop bx
pop ax
pop dx
ret
store_name endp
;*****************************************************************************
store_grade proc
push ax
push si
mov si,0
input:
mov ah,01
int 21h ;輸入字符
cmp al,0dh ;判斷是否輸入回車
je return ;輸入結束
cmp al,' ' ;判斷是否輸入空格
je input ;跳過空格
and al,0fh ;轉換成非壓縮的BCD碼
mov buffer1[si],al
inc si ;輸入未結束,則繼續輸入
jmp input
return:
mov buffer1[si],'$' ;將原來的回車換成結束符
pop si
pop ax
ret
store_grade 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[si],al
inc si
loop next1
;------------------------------------------
;期末成績×0.6+期中成績×0.2+實驗成績*0.1+平時成績*0.1
mov si,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
mov ax,bx
mov cl,10
div cl
;-----------------------------------------------------------------
;將結果轉化為ASCII碼存儲
or ah,30h ;小數部分
mov resultes+2,ah
aam
or al,30h ;轉換為ASCII碼
or ah,30h
mov resultes,ah ;十位
mov resultes+1,al ;個位
;==============================================================================
pop bx
pop dx
pop cx
pop si
pop ax
ret
compute endp
;**************************************************************************
sort proc
ret
sort endp
;*****************************************************************************
display proc
push ax
push dx
lea dx,stars ;顯示一行星號
mov ah,9
int 21h
;---------------------------------------------------------------------------
lea dx,show_result ;顯示輸出結果提示字符
mov ah,9
int 21h
lea dx,student ;顯示學生姓名
add dx,2 ;姓名的首地址
mov ah,9
int 21h
lea dx,maohao ;顯示一個冒號
mov ah,9
int 21h
;-------------------------
mov dl,resultes ;顯示學生平均成績(十位)
mov ah,2
int 21h
mov dl,resultes+1 ;顯示學生平均成績(個位)
mov ah,2
int 21h
mov dl,'.' ;打印小數點
mov ah,2
int 21h
mov dl,resultes+2 ;顯示學生平均成績(小數位)
mov ah,2
int 21h
;-------------------------------------------------------------------
lea dx,stars ;顯示一行星號
mov ah,9
int 21h
pop dx
pop ax
ret
display endp
;****************************************************************************
main endp
;-------------------------------------------------------------------------
code ends
;*************************************************************************
end start
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -