MASM-打字练习程序 发表时间:2024-01-01 来源:明辉站整理相关软件相关文章人气: [摘要]功能:1) 从磁盘文件中读入一些字母(程序中只载入一屏306个字符)2) 运行时,可按照屏幕显示的字母输入练习(模拟金山打字,这个实现很有挑战性哦,先拷贝过去运行下看看效果哦)3) 输完结束或按ESC结束.结束时可显示出练习输入的时间,并显示出正确率. 说明:该程序主要分成(刮弧中为相应主要的函数... 功能: 1) 从磁盘文件中读入一些字母(程序中只载入一屏306个字符) 2) 运行时,可按照屏幕显示的字母输入练习(模拟金山打字,这个实现很有挑战性哦,先拷贝过去运行下看看效果哦) 3) 输完结束或按ESC结束.结束时可显示出练习输入的时间,并显示出正确率. 说明: 该程序主要分成(刮弧中为相应主要的函数块) 1)打字事例文件加载模块(LoadFile )注:加载文件的时候提供绝地路径,而且文件中字符不宜太少,最好多于306个。 2)打字屏幕提示及打字窗口模块(clew_char,isFullLine )注:这里是算法的集中点,注意提示功能和退格功能的实现,特别注意退格时候对字符统计的影响的处理。 3)打字时间及正误统计模块(TONGJI) 注:这里主要注意的是时间的显示和正确率的计算,试试哦自己独立实现下,很有趣的呢。 4)打字结果计算与显示模块( UseTimeAndOut,RightRata_out) 注:怎么把结果显示在屏幕上的呢,汇编中只能输出字符(串)呀,这里的技巧啊,先想想哦(整数123,虽然是一个数可在屏幕上输出''1''''2''''3''可不简单呢,还有带小数的(如98.34)怎么输出呀?嘿嘿想想吧,肯定是要转换的,但这算法.....) 由于是很早前做的东西,当时又没有做好文档注释,现在也没时间重新拣起来.放在硬盘上删了可惜,贴出来至少对刚接触汇编又汇编感兴趣的朋友还是有所帮助的.我做些大致性的标注希望能有所帮助(一般函数名表示该函数的主要实现的功能,宏也类似). 如果代码不能运行,请和我联系:hbyufan@163.com (也可以给我发消息.) 如果代码不能运行,请和我联系:hbyufan@163.com (也可以给我发消息.) ;程序:dazi.asm ;作者:周志明 ; 说明:程序通过masm5运行 ;-------------------------------------------------------------------- ;------------------------------------------ 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 | |