I/O連接埠讀寫的實現

來源:互聯網
上載者:User

細心的讀者會發現,C++ Builder不再支援如inportb()、outportb()一類I/O連接埠讀寫指令了。準確地說,在Windows環境下,Borland C++僅支援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;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.