Главная страница | назад





Article #16609: Inline assembly

 Question and Answer Database
FAQ1609C.txt Inline assembly
Category :IDE
Platform :All
Product :BC++ 5.x
Question:
The PGP 2.6.3i source code tree includes some C functions
which have inline 32-bit assembly. The source files claim that
they require a Microsoft compiler, but I compiled them anyway
using Borland C++ v5.01 and TASM32. To check what it was doing,
I compiled to assembler. The function appears to have been
parsed with prolog/epilog code and C variable references
translated into appropriate assembler references.
Magic! (So far, I've found no reference in the manuals or online
help claiming that BCC32 can do this, given that inline assembly
using BASM is restricted to 16-bit code. I would have expected
this to be advertised somewhere...)
The other part of the code has *inline* C functions implemented
using 32-bit assembly. It appears that this cannot be done using
Borland C++/TASM (although making them out-of-inline functions
works as detailed above). I assume that there is no way to
achieve this?
Answer:
I think the only way to do it is to use __emit__ directive.
It simply emits a byte into the code segment. It allows you to
emit _any_ code. But you can use register names and
getinterrupt() function freely:
#include 
inline int AsmFunction()
{
_EAX = 0;
geninterrupt( 0x85 );
return _EBX;
}
5/13/98 10:46:27 AM

Last Modified: 01-SEP-99