MASM-打字練習(xí)程序 發(fā)表時(shí)間:2024-01-01 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣: [摘要]功能:1) 從磁盤文件中讀入一些字母(程序中只載入一屏306個(gè)字符)2) 運(yùn)行時(shí),可按照屏幕顯示的字母輸入練習(xí)(模擬金山打字,這個(gè)實(shí)現(xiàn)很有挑戰(zhàn)性哦,先拷貝過去運(yùn)行下看看效果哦)3) 輸完結(jié)束或按ESC結(jié)束.結(jié)束時(shí)可顯示出練習(xí)輸入的時(shí)間,并顯示出正確率. 說明:該程序主要分成(刮弧中為相應(yīng)主要的函數(shù)... 功能: 1) 從磁盤文件中讀入一些字母(程序中只載入一屏306個(gè)字符) 2) 運(yùn)行時(shí),可按照屏幕顯示的字母輸入練習(xí)(模擬金山打字,這個(gè)實(shí)現(xiàn)很有挑戰(zhàn)性哦,先拷貝過去運(yùn)行下看看效果哦) 3) 輸完結(jié)束或按ESC結(jié)束.結(jié)束時(shí)可顯示出練習(xí)輸入的時(shí)間,并顯示出正確率. 說明: 該程序主要分成(刮弧中為相應(yīng)主要的函數(shù)塊) 1)打字事例文件加載模塊(LoadFile )注:加載文件的時(shí)候提供絕地路徑,而且文件中字符不宜太少,最好多于306個(gè)。 2)打字屏幕提示及打字窗口模塊(clew_char,isFullLine )注:這里是算法的集中點(diǎn),注意提示功能和退格功能的實(shí)現(xiàn),特別注意退格時(shí)候?qū)ψ址y(tǒng)計(jì)的影響的處理。 3)打字時(shí)間及正誤統(tǒng)計(jì)模塊(TONGJI) 注:這里主要注意的是時(shí)間的顯示和正確率的計(jì)算,試試哦自己獨(dú)立實(shí)現(xiàn)下,很有趣的呢。 4)打字結(jié)果計(jì)算與顯示模塊( UseTimeAndOut,RightRata_out) 注:怎么把結(jié)果顯示在屏幕上的呢,匯編中只能輸出字符(串)呀,這里的技巧啊,先想想哦(整數(shù)123,雖然是一個(gè)數(shù)可在屏幕上輸出''1''''2''''3''可不簡單呢,還有帶小數(shù)的(如98.34)怎么輸出呀?嘿嘿想想吧,肯定是要轉(zhuǎn)換的,但這算法.....) 由于是很早前做的東西,當(dāng)時(shí)又沒有做好文檔注釋,現(xiàn)在也沒時(shí)間重新揀起來.放在硬盤上刪了可惜,貼出來至少對剛接觸匯編又匯編感興趣的朋友還是有所幫助的.我做些大致性的標(biāo)注希望能有所幫助(一般函數(shù)名表示該函數(shù)的主要實(shí)現(xiàn)的功能,宏也類似). 如果代碼不能運(yùn)行,請和我聯(lián)系:hbyufan@163.com (也可以給我發(fā)消息.) 如果代碼不能運(yùn)行,請和我聯(lián)系:hbyufan@163.com (也可以給我發(fā)消息.) ;程序:dazi.asm ;作者:周志明 ; 說明:程序通過masm5運(yùn)行 ;-------------------------------------------------------------------- ;------------------------------------------ COLORCHAR MACRO char,color push ax push bx push cx push dx mov ah,9h mov al,char mov bh,0 mov bl,color mov cx,1 int 10h mov ah,03h mov bh,0 int 10h mov ah,02 add dl,1 int 10h pop dx pop cx pop bx pop ax ENDM BACKCHAR MACRO char,color mov ah,02h mov dl,08h int 21h COLORCHAR char,color ENDM CLEARSCREAM MACRO alz,bhz,chz,clz,dhz,dlz push ax push bx push cx push dx mov al,alz mov bh,bhz mov ch,chz mov cl,clz mov dh,dhz mov dl,dlz mov ah,6h int 10h pop dx pop cx pop bx pop ax ENDM SETGBTYPE MACRO chz,clz push ax push bx push cx push dx mov ch,chz mov cl,clz mov ah,1 int 10h pop dx pop cx pop bx pop ax ENDM SETGB MACRO bhz,dhz,dlz push ax push bx push cx push ax mov bh,bhz mov dh,dhz mov dl,dlz mov ah,2 int 10h pop dx pop cx pop bx pop ax ENDM READGB MACRO bhz push ax push bx push cx push dx mov bh,bhz mov ah,3 int 10h mov gbattr[0],dh mov gbattr[1],dl pop dx pop cx pop bx pop ax ENDM LINEFULL MACRO lmax,lact push ax push bx push cx push dx mov ax,lact cmp ax,0 jz LFEXIT mov dx,0 cwd mov bx,lmax div bx cmp dx,0 jz LNFU jmp LFEXIT LNFU: mov FullFlag,1 LFEXIT: pop dx pop cx pop bx pop ax ENDM TISHI MACRO row,col,addr push ax push dx SETGB 0,row,col mov ah,09h lea dx,addr int 21h pop dx pop ax ENDM ;------------------------------------------ data segment addr db 400 dup(''$'') addrtp db 400 dup(''$'') Anumber dw 0 Enumber dw 0 Rnumber dw 0 LineMax dw 0 LineAct dw 0 FullFlag db 0 gbattr db 4 dup(0) oldgba db 4 dup(0) newirupt dw 2 dup(0) oldirupt dw 2 dup(0) count db 0 Stime db 3 dup(0) Utime db 3 dup(0) temp db 50 dup(0) tempw dw 50 dup(0) path db 50 dup(0) ts00 db ''Load File$'' ts01 db ''Load:$'' ts02 db ''OK?$'' ts03 db ''Path Error! Press any key to reinput!$'' ts1 db ''Stime:$'' ts2 db ''Rrate:$'' ts3 db ''Total Use-Time:$'' ts4 db ''Total Characters:$'' ts5 db ''Correct-Reta:$'' ts6 db ''Press any key to end!$'' data ends code segment assume ds:data,cs:code start: mov ax,data mov ds,ax mov ah,0h mov al,03h ;80*25/16 int 10h ;------------------------------------------ CLEARSCREAM 0,07H,0,0,24,79 CLEARSCREAM 0,5eh,9,14,14,65 TISHI 10,35,ts00 TISHI 12,25,ts01 call LoadFile TISHI 13,45,ts02 mov ah,01h int 21h ;------------------------------------------ CLEARSCREAM 0,07h,0,0,24,79 CLEARSCREAM 0,57h,2,10,23,69 CLEARSCREAM 0,17H,3,12,22,66 CLEARSCREAM 0,70h,4,14,22,64 CLEARSCREAM 0,70h,4,14,11,64 CLEARSCREAM 0,17H,12,14,14,64 CLEARSCREAM 0,70h,13,18,13,35 CLEARSCREAM 0,70H,13,43,13,60 SETGB 0,4,14 SETGBTYPE 0,24 mov di,0 mov cx,0ffffh AD: mov dl,addr[di] cmp dl,''$'' jz A2 push dx mov bp,di CALL isFullLine pop dx mov ah,02h int 21h inc di loop AD A2: mov ah,2ch int 21h mov Stime[0],ch mov Stime[1],cl mov Stime[2],dh SETGB 0,15,14 CALL TONGJI mov cx,0ffffh mov di,0h AS: cmp addr[di],''$'' jnz ASnt00 jmp AEND ASnt00: mov bp,di CALL isFullLine mov bp,di CALL clew_char ;========================================== ;READGB 0 reinput: READGB 0 mov ah,01 int 21h cmp al,27 jnz al27nt jmp exit ;------------------------------------------ al27nt: cmp al,0dh jnz al0dnt SETGB 0,gbattr[0],gbattr[1] jmp reinput al0dnt: cmp al,08 jnz ASnext cmp gbattr[1],14 jnz ASnz ;inc gbattr[1] SETGB 0,gbattr[0],gbattr[1] jmp reinput ASnz: mov ah,02h mov dl,'' '' int 21h mov ah,02h mov dl,08h int 21h dec di ;--------------- dec Anumber push ax mov al,addrtp[di] cmp al,addr[di] jnz AS1nt dec Rnumber AS1nt: pop ax CALL TONGJI ;---------------- mov bp,di CALL clew_char jmp reinput ;------------------------------------------ ;========================================== ASnext: inc Anumber CALL TONGJI mov addrtp[di],al cmp al,addr[di] jnz AER inc Rnumber CALL TONGJI A3: inc di ;loop AS dec cx cmp cx,0 jz AEND jmp AS AEND: jmp exit AER: inc Enumber mov temp[1],al BACKCHAR temp[1],074h jmp A3 exit: CLEARSCREAM 0,07,8,16,17,63 CLEARSCREAM 0,57,10,20,15,59 TISHI 11,24,ts3 call UseTimeAndOut TISHI 12,24,ts4 mov bx,Anumber call btod_out TISHI 13,24,ts5 call RightRata_out TISHI 14,30,ts6 mov ah,08 int 21h ;CALL reset_interrupt mov ah,4ch int 21h ;--------------------------------------------------- LoadFile proc near mov si,0 LFROTA: mov ah,01h int 21h cmp al,0dh jz LoadNext cmp al,08h jz LFBK mov path[si],al inc si jmp LFROTA jmp LoadNext LFBK: cmp si,0 jnz lfnz READGB 0 inc gbattr[1] SETGB 0,gbattr[0],gbattr[1] jmp LFROTA lfnz: mov path[si],0 dec si mov ah,02h mov dl,'' '' int 21h mov ah,02h mov dl,08h int 21h jmp LFROTA LoadNext: mov ah,3dh mov dx,seg path mov ds,dx mov dx,offset path mov al,00 int 21h jc LoadERROR ;bx use to save file code mov bx,ax mov si,0 mov dx,seg addr mov ds,dx mov dx,offset addr mov cx,1 LROT: mov ah,3fh int 21h cmp addr[si],0ah jz LROT cmp addr[si],0dh jz LROT inc dx inc si cmp si,306 jb LROT jmp lfret LoadERROR: TISHI 14,20,ts03 mov ah,01h int 21h CLEARSCREAM 0,5eh,9,14,14,65 TISHI 10,35,ts00 TISHI 12,25,ts01 mov si,0 jmp LFROTA lfret: ret LoadFile endp ;--------------------------------------------------- RightRata_out proc near push ax push bx push cx push dx mov ax,Rnumber mov cx,100 mul cx div Anumber mov bx,ax CALL btod_out push dx mov ah,02h mov dl,''.'' int 21h pop dx mov ax,dx mul cx div Anumber mov bx,ax CALL btod_out mov ah,2h mov dl,''%'' int 21h pop dx pop cx pop bx pop ax ret RightRata_out endp ;--------------------------------------------------- UseTimeAndOut proc near mov ah,2ch int 21h sub dh,Stime[2] jns SecUnBlow jz SecUnBlow add dh,60 dec cl SecUnBlow: sub cl,Stime[1] jns MinUnBlow jz SecUnBlow add cl,60 dec ch MinUnBlow: sub ch,Stime[0] CALL OutTime ret UseTimeAndOut endp ;----------------------------------------------- OutTime proc near ;ch:cl:dh mov al,ch cbw mov bx,ax CALL btod_out mov ah,2h mov dl,''-'' int 21h mov al,cl cbw mov bx,ax CALL btod_out mov ah,2h mov dl,''-'' int 21h mov al,dh cbw mov bx,ax CALL btod_out ret OutTime endp ;--------------------------------------------------- TONGJI proc near push ax push bx push cx push dx mov ax,seg addr mov ds,ax READGB 0 SETGB 0,13,20 CLEARSCREAM 0,70h,13,18,13,35 mov ah,09h lea dx,ts1 int 21h mov ah,2ch int 21h CALL OutTime SETGB 0,13,45 mov ah,09h lea dx,ts2 int 21h mov ax,Rnumber mov bx,ax call btod_out mov ah,2h mov dl,''/'' int 21h mov ax,Anumber mov bx,ax call btod_out SETGB 0,gbattr[0],gbattr[1] pop dx pop cx pop bx pop ax ret TONGJI endp ;---------------------------------------------- btod_out proc near ;num store in bx push ax push cx push dx push bp mov ax,bx mov si,4 rota1: mov bl,10 div bl mov temp[si],ah and ax,00ffh dec si cmp si,0 jnz rota1 mov bp,1 mov si,1 rota2: mov dl,temp[si] add dl,''0'' cmp dl,''0'' jz btodeal mov bp,0 btrt1: mov ah,02h int 21h btrt2: inc si cmp si,4 jna rota2 cmp bp,1 jnz RT mov ah,2h int 21h jmp RT btodeal: cmp bp,1 jz btrt2 jmp btrt1 RT: pop bp pop dx pop cx pop ax ret btod_out endp ;-------------------------------------------------- isFullLine proc near ;bp is the parament push ax push bx mov ah,gbattr[0] mov al,gbattr[1] mov LineMax,51 mov LineAct,bp LINEFULL LineMax,LineAct mov bl,FullFlag cmp bl,0 jz isfexit READGB 0 add gbattr[0],1 sub gbattr[1],51 SETGB 0,gbattr[0],gbattr[1] mov FullFlag,0 isfexit: mov gbattr[0],ah mov gbattr[1],al pop bx pop ax ret isFullLine endp ;-------------------------------------------------- clew_char proc near ; bp is the parament push ax push bx push cx push dx push si READGB 0 mov dh,gbattr[0] mov dl,gbattr[1] mov oldgba[0],dh mov oldgba[1],dl ;4/14,4/64,15/14,15/64 mov ax,bp mov bl,51 div bl mov dh,4 mov dl,14 add dh,al add dl,ah mov temp[0],dh mov temp[1],dl SETGB 0,temp[0],temp[1] COLORCHAR addr[bp],5Eh cmp bp,0 jz resetgb cmp temp[1],14 jz clew2 sub temp[1],1 clew1: mov bx,bp dec bx SETGB 0,temp[0],temp[1] COLORCHAR addr[bx],07dh jmp resetgb clew2: sub temp[0],1 add temp[1],50 jmp clew1 resetgb: SETGB 0,oldgba[0],oldgba[1] pop si pop dx pop cx pop bx pop ax ret clew_char endp ;-------------------------------------------------- code ends end start | |