在C++Builder4.0 中如何用嵌套式汇编的问题(50分)

  • 主题发起人 徐婉璐
  • 开始时间

徐婉璐

Unregistered / Unconfirmed
GUEST, unregistred user!
您好:
在C++Builder4.0 中如何用嵌套式汇编的问题
我用下面代码读一端口,工作正常,但后来在编译时提示[Tasm Fatal Error] Out of hash space

Byte m_InData;
asm{
mov dx,300H
in al,dx
mov m_InData,al
}
为何?

谢谢!
抚顺 徐书华
fsxusuh@mail.fsptt.ln.cn
2000.04.19
 
hash 是不是 哈希 什么的,
看着代码没什么毛病。
 
C++ Builder不支持32位应用下的端口操作
试试下面抄来的代码
void outportb(unsigned short int port,unsigned char value)
{
_emit_(0x8b,0x95,&port);
//mov edx, &port
_emit_(0x8a,0x85,&value);
//mov al, &value
_emit_(0x66,0xee);
//out dx,al
}
void outportw(unsigned short int port,unsigned int value)
{
_emit_(0x8b,0x95,&port);
//mov edx, &port
_emit_(0x66,0x8b,0x85,&value);
//mov ax, &value
_emit_(0xef);
//out dx,ax
}
unsigned char inputb(unsigned short int port)
{
unsigned char value;
_emit_(0x8b,0x95,&port);
//mov edx, &port
_emit_(0x66,0xec,&value);
//in al, dx
_emit_(0x88,0x85,&value);
//mov &value, al
return value;
}
unsigned char inputw(unsigned short int port)
{
unsigned short int value;
_emit_(0x8b,0x95,&port);
//mov edx, &port
_emit_(0xed);
//in ax, dx
_emit_(0x66,0x89,0x85,&value);//move &value, ax
return value;
}
 
1.应该是__emit__
2.内嵌汇编时应该注意保存寄存器等的内容并恢复
Byte m_InData;
asm{
push dx
push ax
mov dx,300H
in al,dx
mov m_InData,al
pop ax
pop dx
}
 
接受答案了.
 
顶部