下面这段小程序是我写的,用来访问PCI 设备中HDA 控制器的一些寄存器内的值.用turb C编译已经OK了,但用VC却不行啊.
// Note:Your choice is C++ IDE
#include "iostream.h"
#include <stdio.h>
#include <conio.h>
typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;
#define PCI_CONFIG_ADDRESS
0xCF8
#define PCI_CONFIG_DATA
0xCFC
#define HDA_address
0x8000D804
#define AUDIO_ADDR1
0x8000D810
//#define AUDIO_ADDR2
0x8000D811
//#define AUDIO_ADDR3
0x8000D812
//#define AUDIO_ADDR4
0x8000D813
#define HDA
0x8000D800
/* 读32位端口 */
DWORD inpd(int portid)
{ DWORD dwRet;
asm mov dx, portid;
asm lea bx, dwRet;
__emit__
(
0x66,0x50, // push EAX
0x66,0xED, // in EAX,DX
0x66,0x89,0x07, // mov [BX],EAX
0x66,0x58); // pop EAX
return dwRet;
}
/* 写32位端口 */
void outpd(int portid, DWORD dwVal)
{
asm mov dx, portid;
asm lea bx, dwVal;
__emit__
(
0x66,0x50, // push EAX
0x66,0x8B,0x07, // mov EAX,[BX]
0x66,0xEF, // out DX,EAX
0x66,0x58); // pop EAX
return;
}
void main()
{
DWORD HDA_04;
DWORD HDA_V;
DWORD
AUDIO_A;
outpd(PCI_CONFIG_ADDRESS,HDA_address);
HDA_04=inpd(PCI_CONFIG_DATA);
//get address1
outpd(PCI_CONFIG_ADDRESS,AUDIO_ADDR1);
AUDIO_A=inpd(PCI_CONFIG_DATA);
//get address2
//outpd(PCI_CONFIG_ADDRESS,AUDIO_ADDR2);
//AUDIO_2=inpd(PCI_CONFIG_DATA);
//get address3
//outpd(PCI_CONFIG_ADDRESS,AUDIO_ADDR3);
//AUDIO_3=inpd(PCI_CONFIG_DATA);
//get address4
outpd(PCI_CONFIG_ADDRESS,HDA);
HDA_V=inpd(PCI_CONFIG_DATA);
printf("The HDA_04 value=%#x%x \n",(WORD)HDA_04,HDA_04>>16);
printf("THE AUDIO BASE ADDRESS IS:%#x%x \n",(WORD)AUDIO_A,AUDIO_A>>16);
printf("%#x%x",(WORD)HDA_V,HDA_V>>16);
}