Borland/Embarcadero inline assembly experience

I happen to be a weirdo that like to make the occasional inline assembly routine just for fun. Over the years I've learned some stuff about inline assembly in C++ Builder, and I figured that if i write it down I might remember it better - some of the things I've had to discover more than once :-)   And since I'm at it I figured maybe someone else might find this useful, so here we go:

General tricks:

32 bit Borland x86

Format:

asm
{
  Instructions
};
for pure assembly function or method use:
Type __declspec(naked) Function(Parameters)
{
  asm
  {
    Instructions:
    RET
  };
};
REMEMBER THE RET INSTRUCTION!!!, it's a nightmare debugging the behavior of a missing RET

Limitations, tips:

32 bit Clang x86

Should be largely the same as BCC64, but isn't quite, it has problems with borlands mangled symbold and their @'s

64 bit x64

Format:

asm(".intel_syntax;"
" Instruction 1;"
" Instruction 2;");
Yes, i know it's EXTREMELY annoying and UGLY. If you leave out the.intel_syntax you get .att_syntax, which, believe it or not, is even more EXTREMELY annoying and UGLY. EDIT: 10 Update 1 status: Error reporting in the message window seems to only be able to highlight the right line for an error if you use "\n" instead of ";"

for pure assembly methods use:
void __fastcall __declspec(naked) Function()
{
  asm(".intel_syntax\n"
  " Instruction 1\n"
  " Instruction 2\n");
};
or use __attribute__((naked)) instead of __declspec(naked)


Currently there is no need to remember the RET instruction, the bugged implementation of the naked attribute adds one, but you might as well be safe, the worst that can happen is a 6.25 % chance of wasting 16 bytes because of alignment.

Limitations, tips:

So the big one: extended assembly

Which specifies outputs, inputs and clobbers after the code like this:
asm("Instructions" : Outputs : Inputs : Clobbers);
Limitations, tips:
Page created by: Sune E. M. Andersen 2015-01-18. Last updated: 2023-08-18..