Considerations for writing and using Intel assembly code in Delphi projects

Third edition - December 2006.

The idea to write this article goes back all the way to the years of Delphi 2. While I was keen to use assembler in some of my projects, I quickly found out that there wasn't much documentation available on the topic of how to properly integrate assembler code into Delphi programmes. I hope this text goes some way towards addressing that particular problem. I have restructured the previous content on the occasion of porting it to this new site. I intend to rewrite the cpuid code very soon as well and additional new material is awaiting a final check before it will be released here too. So keep your eyes on this page.

Note: this is very much a work in progress. I have very little time, so new material is added only from time to time. If there are particular topics that you would like to see addressed, please let me know.

Table of Contents

Introduction: to write assembler or not to write assembler?
Chapter 1: General Context of Assembler Code
1.1. Where to locate the assembler code
1.2. Labels
1.3. Loops
1.4. Entry and exit code
1.5. Register preservation
Chapter 2: Passing Parameters
2.1. Calling Conventions
2.2. Passing parameters in registers
2.3. Using the stack for parameter passing
2.4. Passing by value versus passing by reference
Chapter 3: Local Variables
3.1. Local variables and the stack frame
3.2. Simple types as local variables
3.3. Records as local variables
3.4. Heap allocated types as local variables
Chapter 4: Returning Results
4.1. Returning integers as immediate values
4.2. Returning booleans as immediate values
4.3. Returning real numbers
4.4. Returning characters
4.5. Returning a long string
4.6. Returning records
Appendix A: Further reading

List of tables

Table 1: Use of CPU registers
Table 2: Calling Conventions
Table 3: Parameter Passing
Table 4: Returning results

List of code examples

(tbc)


This page was last updated 2 January 2007.