|
|||||||||||
|
Technical Support On-Line Manuals C166 User's Guide |
C166 User's GuideOperandsThe syntax of the A166 Macro Assembler applies to extended inline assembler blocks. Expressions may be absolute or relocatable as is the case with A166 Assembler Code. OperandsConstants can be written in Assembler or C format, i.e. 0E123H, 0xE123, 256. Assembler Symbols can refer to C identifiers such as automatic, global or external variable names, parameters, labels, enumerations, functions, and registerbank names. For you can refer to a registerbank as shown in the following example:
void FuncRB (void) using __MyBank {
...
}
mov r3,#__MyBank
scxt r3,#__MyBank
The Keil C166 Compiler optimizes the C code and assigns automatic variables and parameters to registers (if possible). When an variable is assigned to CPU registers, you may use it in almost all CPU instructions as direct operand. However, if the variable is located on the user stack or in fixed memory locations, only a few instructions can access this variable. Therefore the legal operand combinations depend on the location of such variables (CPU register, user stack, or fixed memory location). Illegal operand combinations are flagged as error by the C166 Compiler. The instruction combination determined by the C166 Compiler is shown in the listing file. Therefore you should generate a C166 Compiler listing and refer to this listing file in case of errors. The following two examples show legal and illegal instruction set combinations: Example 1: Valid access to a local variable
long lFunc (void) {
long l1 = 0; // l1 is assigned to R6/R7
__asm {
mov r2,#0x5678
mov r1,#0x1234
add word0 l1,r1
add word2 l1,r2
}
return (l1);
}
The instruction ADD WORD0 l1,r1 is converted to ADD R7,R1 which is a valid CPU instruction. The code generated for the above example is shown below: 0000 E006 MOV R6,#00H 0002 E007 MOV R7,#00H ;---- Variable 'l1' assigned to Register 'R6/R7' ---- 0004 E6F27856 mov r2,#0x5678 0008 E6F13412 mov r1,#0x1234 000C 0071 add word0 l1,r1 000E 0062 add word2 l1,r2 Example 2: Invalid access to a local variable This example is almost identical to Example 1 except that the C166 Compiler does not assign the variable to a register due to the lack of an initial assignment.
long lFunc (void) {
long l1; // l1 is not assigned to registers
// because no initial value is present
__asm {
mov r2,#0x5678
mov r1,#0x1234
add word0 l1,r1 ; flagged as error
add word2 l1,r2
}
return (l1);
}
In the previous example, word0 l1 translates to [R0] so the resulting instruction is ADD [R0],R1. This operand combination is not a valid 166 instruction. The instruction is marked as erroneous and details can be reviewed in the listing file: *** add word0 l1,r1 *** ______________^ *** add [Rn+#const],Rn *** ERROR C195 IN LINE 20 OF InlAsm.C: inline-asm: Invalid instruction operand(s) | ||||||||||
|
|||||||||||