大连机车厂官网:如何用汇编计算延时?

来源:百度文库 编辑:神马品牌网 时间:2024/05/05 11:58:38
我的想法是:不停地取cmos ram里那个表示 "当前时间值已经设置好,反之正在更新时钟 "的位,直到“已经设置好”,然后取当前秒,存储起来,然后再不停地取那个位,直到“已经设置好”,然后比较一下现在的秒和存储的那个,如果不相等,则将过去存储的那个秒替换为现在的,然后接着来……有一个计数变量,计算总共的秒数是否满足,请问我这么想对么?

而且,比如说我在不停地取那个位,是否有可能漏过一次该位为1的机会呢?请问一下cmos时钟设置那个位的时间是多少?是瞬间,还是更长?

我给你一个微秒的延吧,不过不要问我为什么,说实话我是从BC里TD出来再修改而成的(只是从逻辑上进行优化):;-----------------------------------------------------------------
;
; Delay.asm
;
; Wait for specified period.
;
;
; Run Time Library for Future Assember
; Revision: 1.02
; Author: Chen Wen-yao
; Date: 2004.10.15
;
; Copyright (c) 1999, 2001 by Futuresoft
; All Rights Reserved.
;
;-----------------------------------------------------------------
include system.inc

MULTIPIER = 1193d*2d

.CODE
assume cs:@Code

;void pascal Delay(unsigned Milliseconds);

public @@Delay

@@Delay proc near
push bp
mov bp,sp
;
push di
push si
;stop=di:si,cur=dx,prev=cx
call __ReadTimer
mov cx,dx
mov ax,[bp+04h]
mov dx,MULTIPIER
mul dx
mov di,dx
mov si,ax
add si,cx
adc di,00h
@begin:
call __ReadTimer
or di,di
jnz @continue
cmp si,dx
ja @continue
@return:
pop si
pop di
pop bp
ret 02h
@continue:
cmp dx,cx
jnb @skip
or di,di
jz @return
dec di
@skip:
mov cx,dx
jmp @begin
@@Delay endp

__nothing proc ;nothing but waste time
ret
__nothing endp

__ReadTimer proc near
;
pushf
cli

mov al,00h
out 43h,al

call __nothing

in al,40h
mov dl,al

call __nothing

in al,40h
mov dh,al

not dx
popf
;
ret
__ReadTimer endp

end