Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15183033
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-31 14:12:47

细心的读者会发现,C++Builder不再支持如inportb()、outportb()一类I/O端口读写指令了。准确地说,在环境下,BorlandC++仅支持16位应用程序的端口操作,对32位应用程序的端口操作不再支持,而C++Builder开发出来的程序是32位的。我个人以为,这是C++Builder设计者的败笔。因为PC机中,I/O地址空间与内存地址空间从来都是各自独立的。看看Delphi,不就通过Port数组实现了对I/O端口的访问了吗?搞不清楚为什么C++Builder就没有提供类似的机制?下面这几个函数是笔者从网上淘下来的,经过验证,在95环境下,的确可实现对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;
}
阅读(330) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~