Example of Using VECTIN Procedure

Product Version(s):
Operating System:   MS-DOS
Flags: enduser |
Last Modified: 24-FEB-1988    ArticleIdent: Q10286

PRODUCT:  PASCAL/3.20

Question:
Please give me an example of how to use the VECTIN procedure.

Response:

program EXAMPLE(input,output);

{******************************************************************
NOTE: THIS PROGRAM USES THE VECTIN PROCEDURE ALONG WITH THE DISBIN
AND ENABIN PROCEDURES.  IT IS INTENDED TO ILLUSTRATE IMPLEMENTING A
SUBSTITUTE DEFAULT DIVIDE BY ZERO ERROR HANDLER.  WHEN THE PROGRAM
RECEIVES A DIVIDE BY ZERO, IT EXECUTES THE PROCEDURE "WORLD" INSTEAD
OF THE NORMAL INTERRUPT 0 PROCEDURE.
*******************************************************************}

{******************************************************************
********** (1) DECLARE VARIABLES AND EXTERNAL PROCEDURES **********
*******************************************************************}

var
     HELLO : word;
     VAR1, VAR2, ZERO : integer;

procedure disbin; extern;
procedure enabin; extern;
PROCEDURE VECTIN(HELLO:word;procedure world[interrupt,public]);extern;
PROCEDURE PTYUQQ (W:word;x:adsmem);extern;

{******************************************************************
***** (2) THIS IS THE PROCEDURE EXECUTED INSTEAD OF THE    ********
*****     NORMAL INTERRUPT 0 PROCEDURE                     ********
*******************************************************************}

procedure world[interrupt,public];
        begin
                {NOTE: WHEN THIS "WORLD" PROCEDURE IS EXECUTED,
                 INSTEAD OF EXECUTING THE NORMAL PROCEDURE, THE
                 FOLLOWING MESSAGE WILL BE PRINTED}

                writeln ('Yea, verily, the vectin procedure worked.');
                write ('Instead of executing the normal divide by zero');
                writeln(' interrupt, a procedure ');
                writeln('printing this message was executed instead.');
        End;

Begin

{******************************************************************
***** (3) THESE EXPLANATORY NOTES WILL BE PRINTED WHEN YOU     ****
*****     EXECUTE THIS PROGRAM.  THEN IT WILL PROMPT YOU FOR   ****
*****     THE INTERRUPT VECTOR NUMBER THAT YOU WANT TO REPLACE ****
*******************************************************************}

writeln(' ');
WRITELN('NOTE:  Please enter the interrupt vector number "0" below.');
writeln(' ');
WRITELN('EXPLANATION: This is because this program causes a divide by
zero,');
writeln(' and interrupt vector type 0 is the divide error exception
handler.');
writeln('If you alter this program to do something else besides a divide');
writeln(' by zero,you could use this program to try altering other
interrupt');
writeln(' vectors.  You can try entering other interrupt numbers into
this');
writeln(' program as it is, but the program will not execute the VECTIN');
writeln(' procedure if you do.');
write('Please enter an interrupt vector number  -->');
        read(hello);

{******************************************************************
***** (4) FIRST YOU HAVE TO DISABLE INTERRUPTS USING DISBIN.     **
*****     YOU THEN REPLACE THE EXISTING DIVIDE BY ZERO INTERRUPT **
*****     HANDLER WITH YOUR PREFERRED PROCEDURE USING VECTIN.    **
*****     YOU THEN ENABLE INTERRUPTS AGAIN, USING ENABIN.        **
*******************************************************************
***** IMPORTANT NOTE: THIS IS A SIMPLE PROGRAM AND DOES NOT SAVE **
***** THE ORIGINAL ZERO INTERRUPT HANDLER                        **
*******************************************************************}

        DISBIN;
        VECTIN(hello,world);
        ENABIN;

{******************************************************************
***** (5) THIS PERFORMS A DIVIDE BY ZERO, WHICH WILL CAUSE THE ****
*****     "world" PROCEDURE TO BE EXECUTED.                    ****
*******************************************************************}

        VAR1 := 1;
        WRITELN('VAR1 := 1');
        ZERO := 0;
        WRITELN('ZERO := 0');
        writeln('var1 / zero = ...');
        writeln(' ');
        VAR2 := var1 div zero;
End.