How to read and write hardware ports in BCB

Source: Internet
Author: User

In BCB, the __emit__ function can be used to embed binary program code directly into the program, so that some low-level operations can be implemented. Because of the low-level of the direct operating system, this method can cause system instability.

The following is a way to read and write hardware ports using the __EMIT__ function.

Read Port
The port parameter is the input port address and value is the return value.
unsigned char __fastcall INPORTB (unsigned short int port)
{
unsigned char value;
__emit__ (0x8b,0x95,&port); Send the port address to the EDX register
__emit__ (0x66,0xec); Read data from the port into the AL register
__emit__ (0x88,0x85,&value); The value in the AL register is supplemented to
return value;
}
//---------------------------------------------------------------------------
Write Port
Port parameter is an output port address and the value parameter is an output value
void __fastcall OUTPORTB (unsigned short int port,unsigned char value)
{
__emit__ (0x8b,0x95,&port); Send the port address to the EDX register
__emit__ (0x8a,0x85,&value); Send value to the AL register
__emit__ (0x66,0xee); Writes the value in the AL register to the port
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.