User`s manual

Dynamic C Users Manual digi.com 177
11.3 Stand-Alone Assembly Code
A stand-alone assembly function is one that is defined outside the context of a C language function.
A stand-alone assembly function has no auto variables and no formal parameters. It can, however, have
arguments passed to it by the calling function. When a program calls a function from C, it puts the first
argument into a primary register. If the first argument has one or two bytes (int, unsigned int,
char, pointer), the primary register is HL (with register H containing the most significant byte). If
the first argument has four bytes (long, unsigned long, float), the primary register is BC:DE
(with register B containing the most significant byte). Assembly-language code can use the first argument
very efficiently. Only the first argument is put into the primary register, while all arguments—including the
first, pushed last—are pushed on the stack.
C function values return in the primary register, if they have four or fewer bytes, either in HL or BC:DE.
Assembly language allows assumptions to be made about arguments passed on the stack, and auto vari-
ables can be defined by reserving locations on the stack for them. However, the offsets of such implicit
arguments and variables must be kept track of. If a function expects arguments or needs to use stack-based
variables, Rabbit recommends using the embedded assembly techniques described in the next section.
11.3.1 Stand-Alone Assembly Code in Extended Memory
Stand-alone assembly functions may be placed in extended memory by adding the xmem keyword as a
qualifier to #asm, as shown below. Care needs be taken so that branch instructions do not jump beyond
the current xmem window. To help prevent such bad jumps, the compiler limits xmem assembly blocks to
4096 bytes. Code that branches to other assembly blocks in xmem should always use ljp or lcall.
#asm xmem
main::
...
lcall fcn_in_xmem
...
lret
#endasm
#asm xmem
fcn_in_xmem::
...
lret
#endasm