A: 

The discussion here (scroll all the way down) suggests that you cannot do this with the built-in assembler.

frogb
Unfortunately, it's not possible to view that discussion without an Experts-exchange membership.
Mason Wheeler
OK, for those that still haven't realized how to read stuff there: Google for the title "Borland Delphi Asm, align 16 problem" and click the first result. If referred from Google the discussion can be viewed.
mghie
While related to my question (the alignment of code), the question you're linking to is primarily concerned with the alignment of data. Nonetheless, I am aware that it is well possible that there really is no alternative to what I outlined in my question.
PhiS
+1  A: 

One thing that you could do, is to add a 'magic' signature at the end of each routine, after an explicit ret instruction:

asm
  ...
  ret
  db <magic signature bytes>
end;

Now you could create an array containing pointers to each routine, scan the routines at run-time once for the magic signature to find the end of each routine and therefore its length. Then, you can copy them to a new block of memory that you allocate with VirtualAlloc using PAGE_EXECUTE_READWRITE, ensuring this time that each routine starts on a 16-byte boundary.

Frederik Slijkerman
That also seems an option, thanks. I'll investigate this approach a bit further.
PhiS
+3  A: 

As of Delphi XE, the problem of code alignment is now easily solved using the $CODEALIGN compiler directive (see http://docwiki.embarcadero.com/RADStudio/en/Align_code_(Delphi) ):

{$CODEALIGN 16}
procedure MyAlignedProc;
begin
..
end;
PhiS