(Author: Qiu Li, 2000 at 13:23 on July 10)
In C Builder, you cannot read and write the OutputB and InputB ports in Turbo C. But we can have two other ways to achieve this. This article describes how to implement port read and write under C Builder and give the source code for both methods. There are two ways to read and write to port under C Builder, one for embedded assembly languages, and the other is the use __emit__ function. 1 Read / write in the in-line assembly language in C Builder, the assembled statement must be included in a parentheses starting with keyword ASM: ASM {assembly statement 1 ...} Using embedded compilation The language program port output function is as follows: void output (unsigned color port, unsigned char value) // port parameter is the output port address, the value parameter is the output value {asm {MOV DX, PORT // Put the port address to the processor DX register In MOV Al, Value // Turn Value to the processor Al register OUT DX, AL // Send the value in the Al register to the port};} The function will write the data VALUE-free data value of 8-bit data VALUE On the port of Port, the data type of Port is unsigned short, 16-bit unsigned short shapes. The port input function is prepared using the embedded assembly language as follows: UNSIGNED CHAR INPORT (UNSIGNED SHORT Port) / / port parameter is the input port address, return to the input value {unsigned char value; asm {mov dx, port // Put the port address to Inline in the processor DX register, DX // from the DX specified port to the Al register in the Al register, value // assigns the value in the Al register to Value}; return value; // Return port data} The function inport reads a single-unsigned 8-bit characteristic data from the port of the address Port, which is only one, the port number. The returned data is the Unsigned Char type, and the value read from the port. 2 The reading and writing of the port through the __emit__ function__emit__ function is generally used. The usage is as follows: void _ _emit_ _ (argument,...); This function is an internal function of C Builder, the argument called the machine language instruction. It is compiled, and the machine language instruction is directly embedded in the target code, and it is not necessary to use the assembly language and assembly compiler. If you want to use the __emit__ function, you must be familiar with the 80x86 processor's machine language instruction. If the calling parameter is an error machine language instruction, the program will be absent, and it is easy to cause a crash.