组装系统时间DOS [英] Assembly system time DOS

查看:104
本文介绍了组装系统时间DOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些代码:

petla:
mov ah,2
int 1ah

mov[sekunda], dh
mov ah, [sekunda]
mov cl, 4
and ah, 11110000b 
shr ah, cl  
mov dl, ah
add dl, '0'
mov ah, 2
int 21h

mov ah, [sekunda]
and ah, 00001111b   
mov dl, ah
add dl, '0'
mov ah, 2
int 21h

jmp petla

sekunda db 0

当我运行该程序时,显示出很多值(秒),如下所示:

When I run this program shows me lot of values (seconds) looks like this:

12
12
12
12
12
13
13

如何修改代码以仅显示一次一值(一秒一值)?

How modify code to show only one time one values ( one seconds one value)?

如何修改代码以每5秒显示一次时间?

How I can modify code to show for example time every 5 sec?

我需要这是我的主要代码,在x秒钟后,其中的某些内容将被更改.

I need this to my main code where after x seconds something will be changed.

推荐答案

请记住,对于计算机而言,秒秒非常很长一段时间(至少在过去40至50年中!).

Remember that seconds are very long periods of time for a computer (Well, for the last 40-50 years at least!)

您的小程序正在非常快地获取时间值,因此它可以每秒获得几千(甚至百万!)次的当前时间.

Your little program is grabbing the time value very quickly, so it can get the current time several thousand (million even!) times a second.

如果只希望输出更改时的输出,请尝试以下操作:(我们正在添加比较)

If you only want an output when it changes, try something like the following: (We're adding a comparison)

petla:
    mov ah,2
    int 1ah             ; get time

    mov ah, [sekunda]   ; retrieve last good value
    cmp ah, dh          ; is it same as last good value?
    jz  pet1a           ; yup, ignore it, loop again!

    mov [sekunda], dh   ; save seconds

    mov ah, [sekunda]   ; get seconds value
    mov cl, 4           ; ready to shift 4 bits
    and ah, 11110000b   ; isolate top nybble
    shr ah, cl          ; shift into low nybble
    mov dl, ah          ; move into proper register for output
    add dl, '0'         ; magically transform into ASCII digit
    mov ah, 2           ; Select 'write char'
    int 21h             ; uh... write char!

    mov ah, [sekunda]   ; hey, this seems familiar!
    and ah, 00001111b   ; isolate lower nybble!
    mov dl, ah          ; no, really.. deja vu!
    add dl, '0'         ; TaaDaa, it's a char!
    mov ah, 2           ; Select 'write char'
    int 21h             ; make it so!

    jmp petla           ; do it again!  (make this a 'ret', see below)

现在,这个小例程将每秒不断地输出一个新值...也许不是很有价值...

Now this little routine will constantly output a new value every second... perhaps not very valuable...

但是等等!还有更多!

如果将LAST指令(jmp pet1a)更改为返回(ret),我们可以将其用作'wait_for_five_seconds'例程的一部分...就像这样:

If you change the LAST instruction (jmp pet1a) to a return (ret), we can use it as part of a 'wait_for_five_seconds' routine... like so:

wait_for_five_seconds:
    mov al,5              ; how many seconds to wait
wait_for_al_seconds:      ; explained below
wait_loop:
    push ax               ; save our counter (al)
    call pet1a            ; this will call pet1a, which will not return until it has displayed a new second value
    pop ax                ; retrieve our counter (pet1a changes value of ah/al/ax, remember?)
    dec al                ; decrease al by one (does not set flags!!)
    or al,al              ; set flags
    jnz wait_loop         ; al=0?  nope, around we go again!
    ret                   ; go back to whomever called us!

现在,如果您想暂停5秒钟,只需调用wait_for_five_seconds,它就会起作用!

Now, if you wanted to pause for 5 seconds, you simple call wait_for_five_seconds and it'll work!

如果您删除pet1a上写出字符的部分...,那么您将有 silent (沉默)延迟一秒钟.暂停有用.

If you remove the part of pet1a that writes the characters out... you then have a silent delay of one second. Useful for pausing.

如果您想暂停17秒该怎么办?嗯,当我们进入wait_loop部分时,我们的延迟基于al的值...所以,如果我们预加载al,然后调用等待位怎么办?

What if you wanted to pause for 17 seconds? Hmmm, our delay is based on the value of al when we enter the wait_loop section... so what if we preloaded al, then called the wait bit?

    mov al, 17                 ; delay for 17 seconds!
    call wait_for_al_seconds   ; delay for whatever number is in al

但是请小心,如果al的值为0 ...则必须一直循环... 0,-1,-2,...- 127,-128、127、126 ... 2,1,0 ...您将暂停256秒! (4分钟16秒!). (请参阅签名数字表示,了解它为什么在-128左右变得怪异)

Be careful though, if al has a value of 0... it has to loop all the way around... 0, -1, -2, ... -127, -128, 127, 126... 2, 1, 0 ... you'd pause for 256 seconds! (4 minutes, 16 seconds!). (See Signed Number Representations for why it went weird around -128)

我希望这会有所帮助,也许会给您一些想法.这不是一个暂停"解决方案,因为它不是确切的延迟,如果您在新的秒针滴答之前致电了pet1a 恰好,则第一次单击的延迟会很小,然后剩下整整几秒钟...因此,所需的5秒延迟可能在4.000001秒到5秒之间.但这是一个开始.

I hope this has helped and perhaps given you some ideas. It's not an idea 'pause' solution since it isn't an exact delay, if you called pet1a just before a new second ticked over, the delay would be teeny-tiny for the first click, then full seconds for the rest... so a desired delay of 5 seconds could be anywhere from 4.000001 seconds to 5 seconds long. But it's a start.

这篇关于组装系统时间DOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆