在32位Open Watcom C中生成FAR跳转指令 [英] Generating FAR jump instruction in 32-bit Open Watcom C

查看:122
本文介绍了在32位Open Watcom C中生成FAR跳转指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一个远跳转指令以跳转到另一个ISR(中断服务程序).我正在开发32位FreeDOS应用程序.

I need to generate a far jump instruction to jump to another ISR(Interrupt Service Routine). I'm developing a 32-bit FreeDOS application.

阅读OW手册( cguide.pdf clr.pdf ),我想出了两种成功编译w/o任何警告或错误.

After reading OW manuals(cguide.pdf and clr.pdf), I figured out two ways that compiled successfully w/o any warning or error.

    /* Code Snippet #1 */

    #pragma aux old08 aborts ;
    void (__interrupt __far *old08)(void);      // function pointer declaration


    void __interrupt __far new08(void) {

           /* Do some processing here ... */

           (*old08)();  /* OW will now generate a jump inst. instead of call*/
     }

我发现的另一种方法是:

The other approach that I figured out is:

      /* Code Snippet #2 */

      static void jumpToOld08(void);         
      # pragma aux jumpToOld08 = \
             ".686p"     \       
             "                DB      0xEA"  \          
             "off_old08       DD      0"     \               
             "sel_old08       DW      0"     ;             


      void __interrupt __far new08(void){

               /* Do some processing here ... */

               jumpToOld08();   
      }

      extern unsigned short sel_old08;
      extern unsigned int off_old08;

      sel_old08 = ( __segment )FP_SEG(old08);
      off_old08 = FP_OFF(old08);        

现在我的问题是,更正确还是以上两种方法中的哪一种?有任何想法或意见吗?

Now my question is which of the above two ways is more correct or better? Any ideas or opinions?

还有其他方法可以做到这一点吗?

Are there any other ways to accomplish this?

推荐答案

interrupt函数总是很远.

就指令本身而言,您手动构建的远距离跳转似乎是正确的,但是,我敢打赌,简单地跳转(而不是调用)不会删除以前由new08()保存在其序言中的内容(这可能是很多寄存器,最重要的是,还有old08()必须返回到的返回地址!

Your manually constructed far jump appears correct as far as the instruction itself is concerned, however, I bet, simply jumping (instead of calling) won't remove the stuff previously saved by new08() on the stack at its prologue (and that's potentially a lot of registers, and most importantly, there's also the return address buried to which your old08() has to return to!).

为什么这么有创造力?

这篇关于在32位Open Watcom C中生成FAR跳转指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆