[TC++] TurboC 呼叫 assembly 副程式

簡單記錄一下,以免要用時忘了:

// pci.h

extern "C" DWORD ReadPCI_DWORD(unsigned long addr);

 // pci.asm

.MODEL  small, c
        	.386
ReadPCI_DWORD 	PROTO C address:DWORD
        	.CODE
ReadPCI_DWORD   PROC  C address:DWORD
             	mov     dx, 0CF8H
             	mov     eax, address
             	out     dx, eax

             	mov     dx, 0CFCh
             	in      eax, dx

             	; return param in DX,AX
             	mov     dx, ax
             	shr     eax, 16
             	xchg    dx, ax
             	ret
ReadPCI_DWORD   ENDP

             	END
// cpp 

#include "pci.h"

typedef unsigned long DWORD;
DWORD data;
DWORD addr = 0x80000000 + (bus << 16) + (device << 11) + (function << 8) + (reg & 0xFC);

data = ReadPCI_DWORD(addr);     

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *