INTERRUPT for Clock Tick Counter Returns Negative Value (59725)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 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 "Push any key to end program."
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&; ":"; low&; "   ";
LOOP UNTIL INKEY$ <> ""
END
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB59725