The USING statement specifies the register bank (0-3) expression to use for encoding the >AR0-AR7 registers. The register bank selected is noted in the object file and the memory area is reserved by the linker. Some 8051 instructions (like PUSH and POP) allow only absolute addresses to be used. The assembler replaces absolute registers (AR0-AR7) with the physical address of the register in the current register bank. So, while the instruction PUSH R0 is not valid, PUSH AR0 is valid. However, the assembler must know which register bank is used so that the correct physical address is calculated. This is the purpose for the USING statement. The USING statement does not generate any code to switch the current register bank. The assembler program must select the correct register bank. For example, the following code selects register bank 2:
PUSH PSW ; save the current register bank
MOV PSW, #(2 SHL 3) ; set register bank 2
.
.
.
POP PSW ; restore saved register bank
The physical address is calculated as follows: (register bank × 8) + register Note - Exercise caution when using the EQU statement to define a symbol for an absolute register (AR0-AR7). When using EQU, the symbol value is calculated at the time it is defined (not when it is used). If the register bank is subsequently changed with the USING statement, the defined symbol will have the incorrect address and the code generated is likely to fail.
|