I/O端口读写的实现
2008-02-23 05:36:39来源:互联网 阅读 ()
细心的读者会发现,C Builder不再支持如inportb()、outportb()一类I/O端口读写指令了。准确地说,在Windows环境下,BorlandC 仅支持16位应用程式的端口操作,对32位应用程式的端口操作不再支持,而C Builder研发出来的程式是32位的。我个人以为,这是C Builder设计者的败笔。因为PC机中,I/O地址空间和内存地址空间从来都是各自单独的。看看Delphi,不就通过Port数组实现了对I/O端口的访问了吗?搞不清楚为什么C Builder就没有提供类似的机制?下面这几个函数是笔者从网上淘下来的,经过验证,在Windows95环境下,的确可实现对I/O端口的读写。读者能够借鉴使用。 void outportb(unsigned short int port,unsigned char value)
{
//move dx,*(&port);
__emit__(0x8b,0x95,&port);
//mov al,*(&value);
__emit__(0x8a,0x85,&value);
//out dx,al;
__emit__(0x66,0xee);
}
void outportw(unsigned short int port,unsigned short int value)
{
//move dx,*(&port);
__emit__(0x8b,0x95,&port);
//mov ax,*(&value);
__emit__(0x66,0x8b,0x85,&value);
//out dx,ax;
__emit__(0xef);
}
unsigned char inportb(unsigned short int port)
{
unsigned char value;
//move dx,*(&port);
__emit__(0x8b,0x95,&port);
//in al,dx;
__emit__(0x66,0xec);
//mov *(&value),al;
__emit__(0x88,0x85,&value);
return value;
}
unsigned short int inportw(unsigned short int port)
{
unsigned short int value;
//move dx,*(&port);
__emit__(0x8b,0x95,&port);
//in ax,dx
__emit__(0xed);
//mov *(&value),ax
__emit__(0x66,0x89,0x85,&value);
return value;
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: 用PcommPro研发串行通信程式
下一篇: 用游戏操纵杆摸拟鼠标
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
