這邊是一段用來存取 I/O 埠的簡單的程式碼範例:
/*
 * example.c: 一個用來存取 I/O 埠的非常簡單的範例
 *
 * 這個程式碼並沒有什麼用處, 他只是做了埠的寫入, 暫停, 
 * 以及埠的讀出幾個動作. 編譯時請使用 `gcc -O2 -o example example.c',
 * 並以 root 的身份執行 `./example'.
 */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
#define BASEPORT 0x378 /* lp1 */
int main()
{
  /* 取得埠位址的存取權限 */
  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
  
  /* 設定埠的輸出資料信號 (D0-7) 全為零 (0) */
  outb(0, BASEPORT);
  
  /* 休息一下 (100 ms) */
  usleep(100000);
  
  /* 從狀態埠 (BASE+1) 讀出資料並顯示結果 */
  printf("status: %d\n", inb(BASEPORT + 1));
  /* 我們不再需要這些埠位址 */
  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
  exit(0);
}
/* 結束 example.c */