User guide

Note
Using physical register names is not recommended, because it constrains compiler register allocation and can cause
less efficient code to be generated. It is usually better to declare C local variables and use these as operands in
inline assembler.
Constants
The constant expression specifier # is optional. If it is used, the expression following it must be constant.
Instruction expansion
The constant in instructions with a constant operand is not limited to the values allowed by the instruction. Instead,
such an instruction is translated into a sequence of instructions with the same effect. For example:
ADD r0, r0, #1023
might be translated into:
ADD r0, r0, #1024
SUB r0, r0, #1
With the exception of coprocessor instructions, all ARM and Thumb instructions with a constant operand support
instruction expansion. In addition, the MUL instruction can be expanded into a sequence of adds and shifts when the
third operand is a constant.
The effect of updating the CPSR by an expanded instruction is:
arithmetic instructions set the NZCV flags correctly.
logical instructions:
set the NZ flags correctly
do not change the V flag
corrupt the C flag.
Labels
C and C++ labels can be used in inline assembler statements. C and C++ labels can be branched to by branch
instructions only in the form:
B{cond} label
You cannot branch to C or C++ labels using BL.
Storage declarations
All storage can be declared in C or C++ and passed to the inline assembler using variables. Therefore, the storage
declarations that are supported by armasm are not implemented.
SWI and BL instructions
SWI and BL instructions must specify exactly the calling standard used. Three optional register lists follow the normal
instruction fields. The register lists specify:
the registers that are the input parameters
the registers that are output parameters after return
the registers that are corrupted by the called function.
For example:
SWI{cond} swi_num, {input_regs}, {output_regs}, {corrupted_regs}
BL{cond} function, {input_regs}, {output_regs}, {corrupted_regs}
An omitted list is assumed to be empty, except that BL always corrupts ip, and lr. The default corrupted list for BL is
r0-r3.
The register lists have the same syntax as LDM and STM register lists. If the NZCV flags are modified you must
specify PSR in the corrupted register list.
4.1.3 Differences between the inline assemblers and armasm
There are a number of differences and restrictions between the assembly language accepted by the inline
assemblers and the assembly language accepted by the ARM assembler. For the inline assemblers:
You cannot get the address of the current instruction using dot notation (.) or {PC}.
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-3