Microsoft KB Archive/63622

Calling MS-DOS Interrupt to Code .01 Second Delay in COBOL

PSS ID Number: Q63622 Article last modified on 07-09-1990

3.00 3.00a MS-DOS

Summary: In a COBOL version 3.00 or 3.00a program for MS-DOS, it is possible to code a delay that is precise to a hundredth of a second. This can be accomplished by calling MS-DOS interrupt X“21”, with function X“2C” (Get time). On the first call, the current minute, second, and hundredth of a second is recorded. Then the MS-DOS interrupt is called within a loop until the required amount of time has elapsed. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS-DOS.

More Information: Interrupt X“21”, function X“2C” requires the following register set: AH (upper byte of AX) = X“2C” This interrupt function returns data in the the following registers: CH (upper byte of CX) = hour (0 through 23) CL (lower byte of CX) = minutes (0 through 59) DH (upper byte of DX) = seconds (0 through 59) DL (lower byte of DX) = hundredths of seconds (0 through 99) Interrupts can be called from COBOL 3.00 and 3.00a via the special subprogram X“84”. For more information about calling interrupts from COBOL, consult Pages 8-4 and 8-5 of the “Microsoft COBOL Compiler 3.0: Operating Guide” for Versions 3.00 and 3.00a. For more information on interrupt 21 hex, function 2C hex, consult Page 386 of “Advanced MS-DOS Programming” by Ray Duncan, Second Edition (Microsoft Press, 1988). The following program (DELAY.CBL), prompts the user to enter the desired delay in seconds. It then sounds two beeps marking the start and finish of the delay period. To compile and link the program, enter the following: cobol delay; link delay;

Code Example
$SET ANS85 DATA DIVISION. WORKING-STORAGE SECTION. *  Function X&quot;2C&quot; of interrupt X&quot;21&quot;. 01 AX               PIC XX          VALUE X&quot;2C00&quot;. 01 BX               PIC XX. *  Hour and minute will be returned in CX. 01 CX. 05 C-H      PIC 99   COMP-X. 05 C-L      PIC 99   COMP-X. *  Seconds and hundredths of second will be returned in DX. 01 DX. 05 D-H      PIC 99   COMP-X. 05 D-L      PIC 99   COMP-X. *  Interrupt X&quot;21&quot;. 01 Interrupt   PIC X           VALUE X&quot;21&quot;. *  Load actual registers with parameters of CALL. 01 Flag        PIC X           VALUE X&quot;FF&quot;. *  Receives user-entered delay time. 01 Delay       PIC 99   COMP-X. *  Receive the starting minute, second, and hundredth second. 01 Minute      PIC 99   COMP-X. 01 Second      PIC 99   COMP-X. 01 Hundredths  PIC 99   COMP-X. PROCEDURE DIVISION. *   Get delay time from user. DISPLAY &quot;Enter delay in seconds (0 - 59): &quot;. ACCEPT Delay. *   Sound beep to start delay period and get the starting *   minute, second, and hundredth of second. CALL X&quot;E5&quot;. CALL X&quot;84&quot; USING Interrupt, Flag, AX, BX, CX, DX. MOVE C-L TO Minute. MOVE D-H TO Second. MOVE D-L TO Hundredths. *   Stay in loop until enough seconds and hundredths of seconds *   have gone by. PERFORM UNTIL ((D-H - Second) = Delay) AND (D-L > = Hundredths) *      Get new time. CALL X&quot;84&quot; USING Interrupt, Flag, AX, BX, CX, DX *       If a new minute has occurred, seconds have flipped back *      to 0. Adding 60 seconds (1 minute) accounts for this. IF C-L NOT = Minute THEN COMPUTE D-H = D-H + 60 END-IF END-PERFORM. *   Sound beep to end delay period. CALL X&quot;E5&quot;. STOP RUN. Copyright Microsoft Corporation 1990.