用汇编语言编写一个打字练习计时程序

用汇编语言编写一个打字练习计时程序,第1张

stacksegment para stack 'stack' 定义堆栈段 db 256 dup(0) 开辟256个字节的空间top label word 定义top与紧接下来的一个字单元的段值和偏移相同stackends stack部分定义完毕data segment para public 'data' 开辟数据段buffer db 16h dup(0)自定义一个长度为十六进制长度为16h的字节bufpt1 dw 0 自定义一个长度为1的字bufpt2 dw 0 自定义一个长度为1的字kbflag db 0自定义一个长度为1的字节prompt db ' *please practise typing*',0dh,0ah,'$'scantab db 0,0,'1234567890-=',8,0 db 'qwertyuiop[]',0dh,0 db 'asdfghjkl',0,0,0,0 db 'zxcvbnm,./',0,0,0 db ' ',0,0,0,0,0,0,0,0,0,0,0,0,0 db '789-456+1230.'evenoldcs9 dw ?oldip9 dw ?str1 db 'abcd efgh ijkl mnop qrst uvwx yz.' 预设一段字母abcd efgh ijkl mnop qrst uvwx

yz. db 0dh,0ah,'$'str2 db 'there are some newspapers on the table.' 预设一段字母there are some

newspapers on the table. db 0dh,0ah,'$'str3 db 'there are some clouds in the sky.'预设一段字母there are some clouds in

the sky. db 0dh,0ah,'$'str4 db 'she always eats her lunch at noon.' 预设一段字母she always eats her

lunch at noon. db 0dh,0ah,'$'str5 db 'i do not like autumn and winter.' 预设一段字母i do not like autumn and

winter.crlf db 0dh,0ah,'$'colondb ':','$'evensaddrdw str1,str2,str3,str4,str5countdw 0sec dw 0min dw 0hoursdw 0save_lc dw 2 dup(?)data endscode segment assume cs:code,ds:data,es:data,ss:stackmain proc far段内的程序调用start: mov ax,stackmov ss,ax mov sp,offset top

push ds 将ds入栈 sub ax,ax将ax清零 push ax 将ax入栈 mov ax,data 将data里面的数据存到ax中 mov ds,ax mov es,ax

mov ah,0mov al,4int 21hmov ah,0bhmov bh,0mov bl,4int 11h mov ah,35h mov al,09h int 21h mov oldcs9,es mov oldip9,bx

push ds mov dx,seg kbint mov ds,dx mov dx,offset kbint mov al,09h mov ah,25h int 21h pop ds

mov ah,35h mov al,1ch int 21h mov save_lc,bx mov save_lc+2,es

push ds mov dx,seg clint mov ds,dx mov dx,offset clint mov al,1ch mov ah,25h int 21h pop ds

in al,21h and al,11111100b out 21h,alfirst: mov ah,0 mov al,3 int 10h

mov dx,offset prompt mov ah,9 int 21h

mov si,0next:mov dx,saddr[si] mov ah,09h int 21h

mov count,0 mov sec,0 mov min,0 mov hours,0

stiforever: call kbget test kbflag,80h jnz endint push ax call dispchar pop ax cmp al,0dh jnz forever mov al,0ah call dispchar

call disptime lea dx,crlf mov ah,09h int 21h add si,2 cmp si,5*2 jne next jmp firstendint: cli push ds mov dx,save_lc mov ax,save_lc+2 mov ds,ax mov al,1ch mov ah,25h int 21h pop ds

push ds mov dx,oldip9 mov ax,oldcs9 mov ds,ax mov al,09h mov ah,25h int 21h pop ds

sti retmain endpclintproc near push ds mov bx,data mov ds,bx

lea bx,count inc word ptr[bx] cmp word ptr[bx],18 jne return call inctadj: cmp hours,12 jle return sub hours,12return: pop ds sti iretclintendpinct proc near mov word ptr[bx],0 add bx,2 inc word ptr[bx] cmp word ptr[bx],60 jne exit call inctexit:retinct endpdisptime proc near mov ax,min call bindec

mov bx,0 mov al,':' mov ah,0eh int 10h mov ax,sec call bindec

mov bx,0 mov al,':' mov ah,0eh int 10h

mov bx,count mov al,55d mul bl call bindec

retdisptime endpbindec proc near mov cx,100d call decdiv mov cx,10d call decdiv mov cx,1 call decdiv retbindec endpdecdiv proc near mov dx,0div cx

mov bx,0 add al,30h mov ah,0eh int 10h

mov ax,dx retdecdiv endpkbgetproc near push bx cli mov bx,bufpt1 cmp bx,bufpt2 jnz kbget2 cmp kbflag,0 jnz kbget3 sti pop bx jmp kbgetkbget2: mov al,[buffer+bx] inc bx cmp bx,16h jc kbget3 mov bx,0kbget3: mov bufpt1,bx pop bx retkbgetendpkbintproc near push bx push ax

in al,60h push ax in al,61h or al,80h out 61h,al and al,7fh out 61h,al

pop ax test al,80h jnz kbint2 mov bx,offset scantab xlat scantab cmp al,0 jnz kbint4 mov kbflag,80h jmp kbint2kbint4: mov bx,bufpt2 mov [buffer+bx],al inc bx cmp bx,16h jc kbint3 mov bx,0kbint3: cmp bx,bufpt1 jz kbint2 mov bufpt2,bxkbint2: cli mov al,20h out 20h,al pop ax pop bx sti iretkbintendpdispchar proc near push bx mov bx,0 mov ah,0eh int 10h pop bx retdispchar endpcode ends end start

我只知道可以用clock()函数和time(NULL)函数,不知道有没有用

两者都要定义头文件:

#include<time.h>

clock()返回当前程序已经运行的时间,(double)clock()/CLOCKS_PER_SEC这一表达式得到的时间以秒作为单位

而time(NULL)返回的是自UTC时间1970年1月1日0点以来经过的秒数,我们经常以它作为参数来初始化随机数种子,即:srand(time(NULL))

练习打字前打开电脑的计时器就可以。

计时器,是利用特定的原理来测量时间的装置。计时器可以用来帮你解决这些问题。 *** 作界面简便易用,提供了基本的计时控制功能,包括:开始计时、停止计时、继续计时、 *** 作界面简便易用复零、调整计时。

计算机(computer)俗称电脑,是现代一种用于高速计算的电子计算机器,可以进行数值计算,又可以进行逻辑计算,还具有存储记忆功能。是能够按照程序运行,自动、高速处理海量数据的现代化智能电子设备。

由硬件系统和软件系统所组成,没有安装任何软件的计算机称为裸机。可分为超级计算机、工业控制计算机、网络计算机、个人计算机、嵌入式计算机五类,较先进的计算机有生物计算机、光子计算机、量子计算机等。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11112096.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存