Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:28:18+00:00 2026-05-27T07:28:18+00:00

I’m trying to re-program instruction vector table. Here is the code I use: #include

  • 0

I’m trying to re-program instruction vector table. Here is the code I use:

#include <stdio.h>

int a=1;
void func();

void keyboard()
{
    printf("\n\nkeyboard!!!\n");
    a=0;
    asm{iret}
}

int main ()
{
    printf("starting...");
    func();
    return 0;
}

      int vectorcs = 0;
 int vectorip = 0;

void func()
{

    printf("\n*****\n");
    asm{
        cli
        mov ax,0
        mov es,ax
        mov bx,36
        mov ax,word ptr es:[bx]
        mov vectorip,ax
        push ax
         mov ax,word ptr es:[bx+2]
        mov vectorcs,ax
        push ax
        mov ax,cs
        mov word ptr es:[bx],offset keyboard
        mov es:[bx+2],ax
        sti
    }
    printf("\n%d %d\n",vectorip,vectorcs);

    while (a) {
    }
    asm {
        cli
        mov es,bx
        mov bx,36
        pop ax
        mov word ptr es:[bx+2],ax
    }
    asm{
        pop ax
        mov word ptr es:[bx],ax
        sti
    }
}

I’m using Turbo C++ 3.0
When I try to run this program, “16 Bit MS-DOS Subsystem: The NTVDM CPU has encountered an illegal instruction.” appears. Then it shows contents of CS, OP, and IP registers. I can’t continue the program. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:28:19+00:00Added an answer on May 27, 2026 at 7:28 am

    What you’re doing is not right for multiple reasons:

    1. Regular C functions can’t be safely used as interrupt service routines because they don’t correctly save, load and restore the CPU registers. They must be declared with the interrupt keyword. And they’ll have iret for you at the end.
    2. Variables that can change in the program asynchronously from interrupt routines must be declared as volatile, otherwise you’re risking to have accesses to them incorrectly optimized out by the compiler.
    3. Your inline assembly code probably corrupts the contents of CPU registers. One thing that’s wrong with this code is that your asm blocks mess with the stack pointer. The first block exits with several extra words on the stack. This may be completely unexpected for the compiler and can break your program. There may be other issues, but I’m not going to check with the compiler documentation which registers must be preserved by inline assembly blocks. I’d avoid doing this altogether and opt for the setvect() function instead.
    4. Calling most of standard library functions from inside of interrupt service routines is asking for trouble because these functions generally aren’t reentrant/thread-safe. They can modify some global variables or states in completely unexpected ways for the rest of the program. The same is true for calling DOS service functions from the interrupt service routines (which your printf() relies on, btw). You can only call those when DOS says it’s OK. It does so via the InDos flag variable and still, not all are safe to call when InDos=0.

    See how to change interrupt vectors, define interrupt service routines and call DOS functions from them, all with Turbo C, in the answer to this question.

    You may also find this question and its answers useful.

    EDIT:

    This is how you do it without dos.h’s functionality with inline asm:

    #include <stdio.h>
    
    volatile int a = 1;
    void interrupt (*pOldInt9)(void);
    void func(void);
    
    void interrupt keyboard(void)
    {
        printf("\n\nkeyboard!!!\n");
    
        asm {
            in  al, 0x60
            in  al, 0x61
            mov ah, al
            or  al, 0x80
            out 0x61, al
            mov al, ah
            out 0x61, al
        }
    
        a = 0;
    
        asm {
            mov al, 0x20
            out 0x20, al
        }
    }
    
    int main(void)
    {
        printf("starting...");
        func();
        return 0;
    }
    
    void func(void)
    {
        printf("\n*****\n");
    
        asm {
            push    bx
            push    es
    
            mov     bx, 9 * 4
            mov     ax, 0
            mov     es, ax
    
            cli
    
            mov     ax, es:[bx]
            mov     word ptr pOldInt9, ax
            mov     word ptr es:[bx], offset keyboard
    
            mov     ax, es:[bx + 2]
            mov     word ptr pOldInt9[2], ax
            mov     es:[bx + 2], cs
    
            sti
    
            pop     es
            pop     bx
        }
    
        while (a) {}
    
        asm {
            push    bx
            push    es
    
            mov     bx, 9 * 4
            mov     ax, 0
            mov     es, ax
    
            cli
    
            mov     ax, word ptr pOldInt9
            mov     es:[bx], ax
    
            mov     ax, word ptr pOldInt9[2]
            mov     es:[bx + 2], ax
    
            sti
    
            pop     es
            pop     bx
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.