分享
 
 
 

MASM-打字练习程序

王朝other·作者佚名  2006-02-01
窄屏简体版  字體: |||超大  

打字练习程序

功能:

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

<<<

学习箴言:

1,最好的学习方法是:先努力的学,然后努力的忘记.

>>>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有