当前位置:天才代写 > tutorial > C语言/C++ 教程 > BCB中如何读写硬件端口

BCB中如何读写硬件端口

2017-11-05 08:00 星期日 所属: C语言/C++ 教程 浏览:714

BCB中操作__emit__函数可以直接将二进制措施代码嵌入措施中,这样就可以实现一些底层的操纵。由于直接操纵系统底层,这种要领大概会导致系统的不不变。

下面是操作__emit__函数读写硬件端口的要领。

//读端口
//port参数为输入端口地点,value为返回值.
unsigned char __fastcall inportb(unsigned short int port)
{
unsigned char value;
__emit__(0x8b,0x95,&port); //把端口地点送到EDX寄存器中
__emit__(0x66,0xec); //从端口中读入数据到AL寄存器中
__emit__(0x88,0x85,&value); //把AL寄存器中的值辅给value
return value;
}
//—————————————————————————
//写端口
//port参数为输出端口地点,value参数为输出值
void __fastcall outportb(unsigned short int port,unsigned char value)
{
  __emit__(0x8b,0x95,&port); //把端口地点送到EDX寄存器中
  __emit__(0x8a,0x85,&value); //把value送到AL寄存器中
  __emit__(0x66,0xee); //把AL寄存器中的值写入端口
}

 

    关键字:

天才代写-代写联系方式