Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
getvect函数未定义_C_Keyboard_Interrupt Handling - Fatal编程技术网

getvect函数未定义

getvect函数未定义,c,keyboard,interrupt-handling,C,Keyboard,Interrupt Handling,我正在试着运行这个程序。它使用中断,当我们按w时,它在键盘缓冲区中用s替换 但是它给出了getvect和setvect函数中的错误。首先,C中的中断函数没有参数,也没有返回值。 列出所有寄存器是一种浪费空间的行为,除此之外,它不应该编译,因为进入中断事件的条目会导致保存当前运行进程堆栈上的所有密钥寄存器 从中断退出时,所有键寄存器(如PC和状态寄存器)都会恢复 编译器将导致保存/恢复中断函数中更改的任何通用寄存器。如果您在这样低的级别上工作,那么您应该确切地知道中断向量的位置,您应该有一个覆盖中

我正在试着运行这个程序。它使用中断,当我们按w时,它在键盘缓冲区中用s替换


但是它给出了getvect和setvect函数中的错误。

首先,C中的中断函数没有参数,也没有返回值。 列出所有寄存器是一种浪费空间的行为,除此之外,它不应该编译,因为进入中断事件的条目会导致保存当前运行进程堆栈上的所有密钥寄存器 从中断退出时,所有键寄存器(如PC和状态寄存器)都会恢复

编译器将导致保存/恢复中断函数中更改的任何通用寄存器。如果您在这样低的级别上工作,那么您应该确切地知道中断向量的位置,您应该有一个覆盖中断向量的代码段和另一个镜像中断向量的代码段。 然后,将当前的中断向量集复制到镜像,然后用一个指向您编写的中断函数的指针替换所需的单个向量。在代码结束时,需要将向量复制回原始向量区域。 可能是您遇到问题的函数为您执行这些操作

来自c.comp新闻组的一篇非常老的帖子可能会有所帮助: 你在混合语言。在Borland C中,中断的类型为

无效中断*

而在Borland C++中,它有类型< /p> 无效中断*

这会影响setvect的参数类型和 根据所使用的语言以相同方式更改的getvect。 显然,你把程序编译成C++程序而不是C程序。 程序,因为根据编译器的消息“oldvec”是


声明为C中断,GETVECT返回C++中断。< P>在C中使用GET/SETVIECT的格式,看起来与C++示例完全不同:
tick_isr_old = getvect(0x08);

setvect(0x08, (void interrupt (*)(void)) tick_isr);

已经提到的,GETVECT和SETVECT的功能仅适用于Borland/Turbo C++。函数的功能是几乎相同的,并且提供了更好的跨编译器Borland /Turbo C++,MS Visual C++ 1,X,开放WATCOM C++的可移植性。它们应该在中定义

下面是它们的使用示例,每秒打印一个“@”:

/*** Includes ***/
#include <stdint.h>  // int*_t, uint*_t 
#include <stdbool.h> // bool, true, false 
#include <dos.h>     // _chain_intr(), _dos_getvect() , _dos_setvect()
#include <stdio.h>   // putchar()


/*** Definitions ***/
#define TICKS_PER_SEC   18ul
#define VECT_TIMER      0x1C

/*** Global Variables ***/
bool timer_hooked = false;
bool timer_1sec_elapsed = false;
uint32_t ticks = 0;
void (interrupt far * OrigTimerH)( );   // vector to original 0x1C handler


/*** Functions ***/
static void interrupt far TimerH( void ) {
   ticks++;
   if ( ticks % TICKS_PER_SEC == 0 ) {
      timer_1sec_elapsed = true;
   }
   _chain_intr( OrigTimerH ); // handler callback
}

void TimerStart( void ) {
   __asm { cli }              // critical section; halt interrupts
   OrigTimerH = _dos_getvect( VECT_TIMER ); // save original vector
   _dos_setvect( VECT_TIMER, TimerH );      // put our handler in the vector
   timer_hooked = true;       // remember that we're hooked if we wanted to unhook
   __asm { sti }              // resume interrupts
}

int main( void ) {
   TimerStart();

   while ( true ) {
      if ( timer_1sec_elapsed ) {
            timer_1sec_elapsed = false;
            putchar('@');
      }
   }
}

getvect\setvect在哪里定义?这些似乎是仅在Turbo/Borland C中可用的非标准C函数。我确实使用了dos.h。这不管用吗?你用的是什么编译器?您必须直接检查编译器文档或头文件,看看它们是否包含这些函数。我正在使用visual Studio。但是,IIRC:中断函数在中断函数声明中有一个“中断”修饰符?
/*** Includes ***/
#include <stdint.h>  // int*_t, uint*_t 
#include <stdbool.h> // bool, true, false 
#include <dos.h>     // _chain_intr(), _dos_getvect() , _dos_setvect()
#include <stdio.h>   // putchar()


/*** Definitions ***/
#define TICKS_PER_SEC   18ul
#define VECT_TIMER      0x1C

/*** Global Variables ***/
bool timer_hooked = false;
bool timer_1sec_elapsed = false;
uint32_t ticks = 0;
void (interrupt far * OrigTimerH)( );   // vector to original 0x1C handler


/*** Functions ***/
static void interrupt far TimerH( void ) {
   ticks++;
   if ( ticks % TICKS_PER_SEC == 0 ) {
      timer_1sec_elapsed = true;
   }
   _chain_intr( OrigTimerH ); // handler callback
}

void TimerStart( void ) {
   __asm { cli }              // critical section; halt interrupts
   OrigTimerH = _dos_getvect( VECT_TIMER ); // save original vector
   _dos_setvect( VECT_TIMER, TimerH );      // put our handler in the vector
   timer_hooked = true;       // remember that we're hooked if we wanted to unhook
   __asm { sti }              // resume interrupts
}

int main( void ) {
   TimerStart();

   while ( true ) {
      if ( timer_1sec_elapsed ) {
            timer_1sec_elapsed = false;
            putchar('@');
      }
   }
}