目的:
編寫英文打字練習(xí)軟件,綜合復(fù)習(xí)字符輸入和顯示利耍,置光標(biāo)、開窗口、顏色設(shè)置等屏幕功能隘梨;掌握分支程序中字符比較及統(tǒng)計(jì)的程序設(shè)計(jì)程癌,循環(huán)及排序程序設(shè)計(jì)方法;加入中斷調(diào)用的計(jì)時(shí)功能轴猎。通過上述綜合性訓(xùn)練嵌莉,進(jìn)一步加深對匯編語言的理解和提高程序設(shè)計(jì)技能。
內(nèi)容:
1.屏幕出現(xiàn)打字練習(xí)菜單(格式自定捻脖,字體锐峭、字號、顏色)
2.菜單項(xiàng)目為4項(xiàng):照打可婶,覆蓋打沿癞,名次,退出
程序框圖:
代碼實(shí)現(xiàn)
```
data segment
menu? db 0ah,0dh,' Input number to chose your function'
db 0ah,0dh,' ? ? ? 1.Follow Typing'
db 0ah,0dh,' ? ? ? 2.Cover Typing'
; db 0ah,0dh,' ? ? ? 3.Ranking'
db 0ah,0dh,' ? ? ? 3.Exit'
db 0ah,0dh,'Please input your select:$'
mess1 db 0ah,0dh,' This is the Follow Typing page.'
db 0ah,0dh,' ? ? Please input accordance with those word!$'
mess2 db 0ah,0dh,' This is the Cover Typing page.'
db 0ah,0dh,' ? ? Please input accordance with those word!'
db 0ah,0dh,' (Yellow is right, Red is wrong!)$'
mess3 db 0ah,0dh,'This is third select$'
mess4 db 0ah,0dh,' Thank you for your use!$'
mess5 db 0ah,0dh,'Your right number is:$'
endline db 0ah,0dh,'$'
mess? db 255,?,255 dup(?)
text? db 'New strides have been taken in strengthening national defense and army building.$'
right db '0$'
sum? db '/80$'
num? db 0
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
let0:
mov ax,0
mov dx,offset menu ;顯示菜單
mov ah,9
int 21h
mov ah,1 ;輸入選擇
int 21h
cmp al,'1' ;輸入為1,跳轉(zhuǎn)到照打界面
jz prog1
cmp al,'2' ;輸入為2,跳轉(zhuǎn)到覆蓋打界面
jz prog2
cmp al,'3' ;輸入為3,跳轉(zhuǎn)到名次界面
jz prog3
jmp prog4 ;輸入不為1或2或3,退出程序
prog1:
jmp real_prog1
prog2:
jmp real_prog2
prog3:
jmp real_prog3
prog4:
jmp real_prog4
real_prog1: ;照打界面
mov ax,0003h ;清屏
int 10h
mov dx,offset mess1 ;顯示提示信息
mov ah,9
int 21h
mov dx,offset endline ;換行
int 21h
mov dx,offset endline ;換行
int 21h
mov dx,offset text ;顯示文章
mov ah,9
int 21h
mov dx,offset endline ;換行
int 21h
mov dx,offset mess ;輸入串
mov ah,10
int 21h
;輸入完畢,開始進(jìn)行循環(huán)比較
mov ax,0
mov di,0 ;存儲(chǔ)正確個(gè)數(shù)
mov cl,mess+1 ;輸入的字母個(gè)數(shù),即循環(huán)的次數(shù)
mov bx,2 ;第一個(gè)字符的單元位置
let1:
mov dl,text[bx-2]
cmp mess[bx],dl ;判斷是否輸入正確
jz let2 ;輸入正確 跳到let2
jmp out1 ;跳到公共出口 out1
let2: ;正確數(shù)+1
add ax,1
add di,1
out1:
dec cl ;循環(huán)次數(shù)-1
inc bx
cmp cl,0
jnz let1
jz out2
out2: ;檢查結(jié)束,輸出結(jié)果
mov dx,offset mess5
mov ah,9
int 21h
;輸出正確個(gè)數(shù)
mov ax,di
mov bl,10
div bl
add ah,'0'
mov right,ah
add al,'0'
mov dl,al
mov ah,2
int 21h
mov dl,right
mov ah,2
int 21h
mov right,0 ;重置right為0
mov di,0
mov dx,offset sum
mov ah,9
int 21h
jmp let0 ;返回選擇菜單
real_prog2: ;覆蓋打界面
mov dx,offset mess2
mov ah,9
int 21h
mov ax,0003h ;清屏
int 10h
;置顯示光標(biāo)
mov ah,2
mov dh,4
mov dl,0
mov bh,0
int 10h
;顯示串
mov dx,offset mess2
mov ah,9
int 21h
mov dx,offset endline ;換行
int 21h
mov dx,offset endline ;換行
int 21h
mov dx,offset text
mov ah,9
int 21h
;置輸入光標(biāo)
mov ah,2
mov dh,9
mov dl,0
int 10h
mov si,80 ;循環(huán)次數(shù)
mov bx,0 ;第一個(gè)字符的單元位置
mov di,0 ;正確個(gè)數(shù)
mov num,0 ;顯示列的位置
prog2_let1:
;輸入字符
mov ah,1
int 21h
mov dl,text[bx]
cmp al,0DH ;判斷是否輸入回車
jz prog2_out2
cmp al,dl ;判斷是否輸入正確
jz prog2_let2 ;輸入正確 跳到let2
cmp al,dl
jnz prog2_let3 ;輸入錯(cuò)誤,跳到let3
jmp prog2_out1 ;跳到公共出口out1
prog2_let2:
add di,1 ;正確數(shù)+1
;輸入正確,改變?yōu)辄S色
mov ah,06h
mov al,0
mov bh,0eh
mov ch,8
mov cl,num
mov dh,9
mov dl,num
int 10h
;置顯示光標(biāo)
mov ah,2
mov dh,9
mov dl,num
mov bh,0
int 10h
mov dl,text[bx]
mov ah,2
int 21h
jmp prog2_out1 ;跳到公共出口out1
prog2_let3:
;輸入錯(cuò)誤,響鈴
mov ah,2
mov dl,7
int 21h
;輸入錯(cuò)誤,改變?yōu)榧t色
mov ah,06h
mov al,0
mov bh,04h
mov ch,8
mov cl,num
mov dh,9
mov dl,num
int 10h
;置顯示光標(biāo)
mov ah,2
mov dh,9
mov dl,num
mov bh,0
int 10h
mov dl,text[bx]
mov ah,2
int 21h
jmp prog2_out1 ;跳到公共出口out1
prog2_out1:
dec si ;循環(huán)次數(shù)-1
inc bx
inc num
cmp si,0
jnz jump_prog2_let1 ;si≠0,繼續(xù)循環(huán)
jz prog2_out2
jump_prog2_let1:
jmp prog2_let1
prog2_out2: ;循環(huán)結(jié)束,輸出結(jié)果
mov dx,offset mess5
mov ah,9
int 21h
;輸出正確個(gè)數(shù)
mov ax,di
mov bl,10
div bl
add ah,'0'
mov right,ah
;add al,74
add al,'0'
mov dl,al
mov ah,2
int 21h
mov dl,right
mov ah,2
int 21h
mov right,0 ;重置正確個(gè)數(shù)為0
mov di,0
mov dx,offset sum
mov ah,9
int 21h
jmp let0
real_prog3: ;名次界面
mov dx,offset mess3
mov ah,9
int 21h
jmp let0 ;返回選擇菜單
real_prog4: ;退出
mov dx,offset mess4
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
```