여기에는 I/O 포트를 엑세스할수 있는 간단한 예제 코드가 있다.
/* * example.c: 간단한 포트 입출력 예제 * * 이 코드는 특별히 쓸만한 건 없고 , 포트에 쓰고, 잠시 멈춘 다음, * 포트를 읽는다. `gcc -O2 -o example example.c'로 컴파일한다. */ #include <stdio.h> #include <unistd.h> #include <asm/io.h> #define BASEPORT 0x378 /* lp1 */ int main() { /* Get access to the ports */ if (ioperm(BASEPORT,3,1)) {perror("ioperm");exit(1);} /* Set the data signals (D0-7) of the port to all low (0) */ outb(0,BASEPORT); /* Sleep for a while (100 ms) */ usleep(100000); /* Read from the status port (BASE+1) and display the result */ printf("status: %d\n",inb(BASEPORT+1)); /* We don't need the ports anymore */ if (ioperm(BASEPORT,3,0)) {perror("ioperm");exit(1);} exit(0); } /* end of example.c */