Microsoft KB Archive/59725

= INTERRUPT for Clock Tick Counter Returns Negative Value =

Article ID: 59725

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q59725



SUMMARY
Interrupt 1Ah, with Function 0, returns the current value of the clock tick counter in registers CX and DX. When the low-order portion of the clock tick counter (returned in DX) exceeds 32,767, it becomes negative when stored as an integer in Basic, because 32,767 is the maximum value for a 2-byte signed integer. Listed below is an example to convert the negative value to the equivalent unsigned long integer value.



MORE INFORMATION
For a more complete description of converting negative signed integers to unsigned integers, query on the following words:

CALL and INTERRUPT and negative and signed and integer

The following Basic program outputs only positive values by removing the sign bit and adding the remaining number plus 1 to 32,767:

Example
' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program.

' To run this program in the VBDOS.EXE environment, you must invoke ' the environment with the /L switch to load the default Quick ' library for Visual Basic for MS-DOS 1.0: ' VBDOS.EXE /L

' To use CALL INTERRUPT in this program, you must do the following: ' If you run this program in QB.EXE, use QB /L QB.QLB. ' If you run this program in QBX.EXE, use QBX /L QBX.QLB. ' LINK with QB.LIB (or QBX.LIB for Basic PDS 7.0).

' Use the following include file for Visual Basic for MS-DOS 1.0: REM $INCLUDE: 'vbdos.bi' ' Use the following include file for QuickBasic for MS-DOS: ' $INCLUDE: 'qb.bi' ' Use the following include file for Basic PDS for MS-DOS: ' $INCLUDE: 'qbx.bi'

DIM inregs AS regtype, outregs AS regtype LOCATE 23, 1: PRINT &quot;Push any key to end program.&quot; DO inregs.ax = 0 CALL interrupt(&H1A, inregs, outregs) high& = outregs.cx low& = outregs.dx IF low& < 0 THEN             ' If the low-order portion is negative: low& = low& AND &H7FFF     ' remove sign bit. low& = low& + &H7FFF + 1   ' Add remaining number plus 1 to 32,767. END IF LOCATE 24, 1: PRINT high&; &quot;:&quot;; low&; &quot;  &quot;; LOOP UNTIL INKEY$ <> &quot;&quot; END

Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB59725

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.