Home > Writings > Programming > Using Assembler in Delphi > Table 1: Use of CPU registers

Using Assembler in Delphi

Table 1: Use of CPU registers

This table summarises register usage in Delphi 32-bit applications. The first column lists the different CPU registers. The second column shows what the register contains upon entry and the third indicates what the register holds upon exit. The fourth column tells you whether or not you are allowed to use the register inside your own code and the last column indicates if you need to preserve the content of the register (save it upon entry and restore it before leaving).

  Entry Exit Use allowed? Preserve?
eax Self (1), First parameter (2) or undefined (3) Function result (4) yes No
ebx Unknown n/a yes Yes
ecx Second parameter (1), Third parameter (2) or undefined (3) n/a yes No
edx First parameter (1), Second parameter (2) or undefined (3) For Int64 result type: highest dword, otherwise n/a yes No
esi Undefined n/a yes Yes
edi Undefined n/a yes Yes
ebp Stack frame pointer Stack frame pointer yes(5) Yes
esp Stack pointer Stack pointer yes(5) Yes
cs Code selector n/a no Yes
ds Data selector n/a no Yes
es Data selector n/a no Yes
fs Thread information block (TIB) selector n/a no Yes
gs Reserved n/a no Yes
ss Stack selector Stack selector no Yes

(1) Upon entry of methods when using the Register calling convention.
(2) Upon entry of stand-alone functions and procedures while using the Register calling convention.
(3) Upon entry for methods and stand-alone functions and procedures in all calling conventions except Register.
(4) Only for Result types that qualify to go into a register. See table 4 for a complete overview of how results are returned to the caller.
(5) While you are allowed to use these registers inside your code, such practise is strongly discouraged. The stack pointer itself changes with every stack operation and its content is therefore highly volatile, making it difficult to manage in code. The ebp register is used to access the stack frame and other uses are therefore to be avoided.