Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Chapter 11 - Classic 68K Runtime Conventions

Classic 68K Stack Structure and Calling Conventions

The classic 68K runtime architecture uses a stack-based parameter-passing system, as shown in Figure 11-1.

Figure 11-1 A 68K stack frame before and after calling a routine

The stack grows from high-memory addresses towards low-memory addresses. The end that grows or shrinks is usually referred to the "top" of the stack, despite the fact that it is at the lower end of memory occupied by the stack.

The boundaries of the stack are defined by two pointers:

Parameters passed by a routine are always placed on the stack above the frame pointer, while local variables are always placed below the frame pointer. Data passed onto the stack is always aligned to 2 bytes. If you pass a single-byte parameter (such as a single character), a padding byte is added by decrementing the stack pointer by 2 bytes instead of 1 (the padding byte is the most significant byte).

The classic 68K runtime environment supports many non-standard calling conventions. For example, C calling conventions can vary depending on the type of call (some system calls have their own conventions) and the development environment. However, in C you can specify Pascal conventions for a routine by using the pascal keyword. Pascal calling conventions are standardized and supported in all 68K development environments.

For example, the routine declared in C as

int mooFunc(UInt8, double);
uses C calling conventions, while

pascal int mooFunc(UInt8, double);
uses Pascal calling conventions.

These parameter passing conventions are part of Apple's standard for procedural interfaces. Object-oriented languages may use different rules for their own method calls. For example, the conventions for C++ virtual function calls may be different from those for C functions.

Pascal Calling Conventions
SC Compiler C Calling Conventions
Register Preservation

Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997

Get information on Apple products.
Visit the Apple Store online or at retail locations.

Copyright © 2004 Apple Computer, Inc.
All rights reserved. | Terms of use | Privacy Notice