"inline" assembly in Borland C++ Builder

Started by
5 comments, last by xeos 23 years, 11 months ago
I''m currently porting some MS VC code to Borland C++ Builder 3, but I have a small problem. The source includes it''s own profiling system, which I''d like to keep, and some functions use either asm, _asm or __asm to include some assembly in the source. For instance, w64 get_system_clock() { w32 lo, hi; __asm { __emit 0x0F __emit 0x31 mov lo, eax mov hi, edx }; return (((w64)hi)<<32) / lo; } ... is designed to return the current system time. But when I try to compile this code, I''m told that the compiler will restart in ASM mode. However, once the file has finished, the compiler stops, and no error messages or warnings are displayed. I am completly stumped! Is there something I can do in order to make it compile, or will I have to redo the code in C++, and thus sacrifice speed, or is there another option? Any help will be greatfully appreciated Simon Wilson
XEOS Digital Development - Supporting the independant and OpenSource game developers!
Advertisement
If the file compiles without errors or warnings, then there''s no problem. Whether it actually works at runtime is another thing. AFAIK, a second pass to compile in the ASM code is not necessary. C/C++ compilers compile source code in one pass, if I''m not mistaken.

So, if there are no errors/warnings, it compiles just fine.

Erik
I''m not sure if there should be a problem running the code, but I remember reading somewhere, I think, that the old Borland compilers (maybe as late as BCB 3) used to compile the C++ code to asm, then compile the whole file as an asm file, including your inline code.

Hope this helps!
Although I don''t know alot about TASM32(BCB)...

I tried to compile the source you posted, but BCB5 professinal couldn''t. (assumes w64 means unsigned __int64, and w32 does unsigned long) Now, I know that ''__emit__'' means embedding immediately data into the program, and ''__emit__( 0x01 );'' in BCB is converted ''db 1'' in ASM (Actually I tested with BCB5 )

How about defining ''db'' as ''__emit'' under BCB? Hope this helps.

Kwanji
Some some reason, BCB3 standard doesn''t come with TASM32. Could the Borland C++ command-line compiler work with BCB3?

When I compile the source, for each asm block encountered, a message saying that it will restart using assembly, and help states:

" The compiler encountered an asm with no accompanying or #pragma inline statement.

The compile restarts using assembly language capabilities. "

Once the file with the assembly has compiled, the compiler stops. Does this mean I need TASM? Or is there another problem

Thanks to all who posted!
XEOS Digital Development - Supporting the independant and OpenSource game developers!
w64 get_system_clock( void )
{
__emit__( 0x0f ); // embeds ''rdtsc''
__emit__( 0x31 );
w32 lo = _EAX;
w32 hi = _EDX;
return ( ( (w64)hi ) << 32 ) / lo;
}

Here is another solution by using ''pseudo-register variables''. (I don''t know their correct name in English. Correct me if I''m wrong ) Probably, this code can be compiled only with C/C++ compiler made by Borland.

BTW I once read an article to the effect that someone installed Borland C++ compiler 5.5 into BCB3/4 environment. According to his/her saying, it worked almost through, but some trouble occurred.

Kwanji - a game developer in Japan
The following is a routine I wrote that compiles with Builder, it answers your questions (I think):

#pragma inline
double Sine(double d)
{
asm {
lea eax,d;
fld qword ptr [eax];
fwait;
db 0xd9; // fsin
db 0xfe;
fwait;
}
}


---
Rob

See other worlds at http://www.silverfrost.com
---RobSee other worlds at http://www.silverfrost.com

This topic is closed to new replies.

Advertisement