asm keyword starts a block of assembler
Tips and Tricks
asmblock is a statement, and you can use it anywhere that calls for a Pascal statement or block, such as the body of a subroutine.
You can refer to variable names within the assembly block and jump to labels declared elsewhere in the procedure. Do not jump into a loop unless you know what you are doing. A label that starts with an
@sign is local to the subroutine and does not need to be declared.
Delphi’s built-in assembler tends to lag behind the technology, so you cannot usually rely on having the latest and greatest instruction set. Instead, you can use
DDdirectives to compile the opcodes manually.
asmblock can change the
EDXregisters, but must preserve the values of
ESP. As a rule, you should not assume that any registers contain special values, but if you are careful, you can access a subroutine’s parameters in their registers. See the calling convention directives (
stdcall) to learn how arguments are passed to a subroutine.
Writing assembly code by hand rarely gives you better performance. The most common reason to use an
asmblock is to use instructions that are not available in Delphi, such as the CPUID instruction shown in the example.
unit cpuid; // CPU identification. // This unit defines the GetCpuID function, which uses the CPUID ...