Keil Logo

USING Assembler Statement

Arguments
USING expression
Description

The USING statement specifies which register bank (0-3) is used to encode the AR0-AR7 registers. The selected register bank 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. While the instruction PUSH R0 is not valid, PUSH AR0 is valid. However, the assembler must know which register bank is used to calculate the correct physical address. 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

  • Carefully use the EQU statement to define a symbol for an absolute register (AR0-AR7). The symbol value is calculated at the time it is defined (not when it is used). If the register bank is changed subsequently with the USING statement, then the defined symbol will have the incorrect address and the code generated is likely to fail.
See Also

EQU

Example
USING   3     ; select register bank 3
PUSH    AR2   ; push R2 in bank 3 (address 1Ah)

USING   1     ; select register bank 1
PUSH    AR7   ; push R7 in bank 1 (address 1Fh)
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.