TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: GLEN MCNABB
from: BRIAN MCCLOUD
date: 1997-03-21 05:04:00
subject: NOP and clocks...

GM>Hi Nick,
GM>        I have been reading several messages about NOP nmenonic.
GM>Here's my two cents. (less rebates :)
GM>        NOP instruction for any better term is equivalent to XCHG AL, AL.
Actually, it's equivalent to XCHG (E)AX, (E)AX.
XCHG AL, AL is encoded as 86 C0 (hex).
GM>There are several XCHG instructions that vary from which register to
GM>register size. IE: byte vs. word vs. etc.... The whole point of an
GM>NOP nmenonic is to create a delay. The accuracy of the delay depends
GM>on the microprocessor and the operating system. An NOP instruction
GM>will be faster (time wise) on a 500mhz ZORBO micro than a 1mhz ZORBO.
GM>        Generally to make an NOP a more accurate timer you must sample
GM>the nmenonic against a reference. The timer is a good one.
GM>        Determine in software the "average" number of NOP instructions
GM>that can be executed between timer ticks by using a hook into the
GM>timer interupt and a loop of NOP's. This can be used to determine
GM>the specific number of NOP's for specific time delays and the micro's
GM>speed as well.
If you want to delay a specific number of clock ticks, this should work about
right:
        MOV     AX, 0040H
        MOV     ES, AX
        MOV     DI, 006C
        MOV     BX, ES:[DI]
        ADD     BX, [DelayAmt]
@@1:    CMP     BX, ES:[DI]
        JNZ     @@1
Or you could use the timer chip:
In the initialization part:
        MOV     AL, 10110110B   ; channel 2, r/w 2 bytes, mode 3, binary
        OUT     43H, AL
        IN      AL, 61H
        AND     AL, FEH
        OUT     61H, AL         ; no sound via this chip at the moment
                                ; OR with 01 instead for sound control
        MOV     AX, 1193        ; about 1000 pulses/sec
        OUT     42H, AL         ; send low byte to channel 2
        MOV     AL, AH
        OUT     42H, AL         ; send high byte to channel 2
...
Delay   PROC    MILLISECONDS : WORD
        MOV     AL, 10110110B   ; channel 2, r/w 2 bytes, mode
        OUT     43H, AL
        IN      AL, 61H
        AND     AL, FEH
        OUT     61H
        MOV     BX, [MILLISECONDS]
        IN      AL, 42H         ; get first low byte
        MOV     AH, AL          ; move high byte temporarily
        IN      AL, 42H         ; get first high byte
        XCHG    AH, AL
        ADD     BX, AX
@@1:
        IN      AL, 42H         ; get low byte
        MOV     AH, AL          ; move high byte temporarily
        IN      AL, 42H         ; get high byte
        XCHG    AH, AL
        CMP     AX, BX          ; have we delayed enough yet?
        JB      @@1             ; when ax < bx, we need to delay more
Delay   ENDP
Neither of those is very dependent on processor speed.  Both of them would
take just about as long on any 80x86 processor (+/- a few microseconds at
most).
((Cloud))
 * OLX 2.2 * If all else fails...lower your standards.
--- PCBoard (R) v15.3/M 10
---------------
* Origin: Next time, Dial The Wrong Number! (209) 943-1880 (1:208/205)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.