Base register directive Format .BASE Rn [,base_expression]
1 – Parameters
Rn One of the base registers, R0 through R30, FP, and SP. base_expression The base address, which is optional, and can be one of the following: o An absolute expression o A relocatable expression o An external expression An expression must not contain forward references or implicit external symbols. An implicitly defined external symbol is a symbol that the assembler defaults to an external symbol. This occurs when the assembler encounters references to a symbol, but does not encounter a definition for the symbol or an .EXTERNAL directive that declares the symbol.
2 – Description
The .BASE directive is used to inform the assembler that a specified base register contains a specified base address. Later in your program, the assembler allows you to implicitly reference the specified base register. When the assembler knows which base addresses are stored in one or more base registers, it can convert an expression to an offset from one of the base registers previously specified in a .BASE directive. .BASE provides a convenient and more readable shorthand for accessing memory and constant values using base registers. .BASE also makes it easier for you to change your register assignments if you later modify your code. The base expression is optional. If the base expression is specified, this base address value is assumed by the assembler to be in the specified register, Rn. If the base expression is omitted, the contents of the specified base register, Rn, is considered undefined until a new base expression is associated with the base register. R31 is defined to always contain 0, according to the architecture definition. Therefore, R31 is known to be a predefined base register containing 0. For every assembly, the assembler assumes the following statement: .BASE R31, 0 Because the contents of R31 cannot change, you cannot specify a base address for R31. You can use the .BASE directive to implicitly reference base registers. You can also automatically compute offsets from a base address known to be in a register to a base address you use in an instruction argument. Most of the memory format Alpha instructions are defined such that one of their arguments must have a base register and an offset. If the assembler encounters only an expression with no base register, the assembler attempts to find a base register that contains a base address or constant within a 16-bit signed offset of the value of the expression. If it finds such a base register, the assembler computes an offset that, when added to the value of the base register, results in a value equal to the expression specified in the instruction argument.
3 – Examples
Example 1 .EXTERNAL COMM_AREA 1 .BASE R1, COMM_AREA 2 CURR_LINE = COMM_AREA + 0 CURR_COLUMN = COMM_AREA + 4 CURR_MODE = COMM_AREA + 8 LDA R4, 17 ; LDA R4, 17(R31) 3 LDL R2, CURR_LINE ; LDL R2, 0(R1) 4 LDL R3, CURR_COLUMN ; LDL R3, 4(R1) STL R4, CURR_MODE ; STL R4, 8(R1) 1 This statement declares an external symbol, COMM_AREA. COMM_AREA is a global symbol that represents the base address of a three-longword communication area that is used by different routines in the program. 2 This statement informs the assembler that base register R1 contains the base address, COMM_AREA, of this communication area. The next three statements define variables within the communication area. 3 The first instruction shows how you can load registers with constant values in the range -32,768 to +32,767 by implicitly using R31 as the base register. 4 The last three statements show how the .BASE directive allows you to implicitly reference base registers and automatically compute offsets. In each of these instructions, the second argument is defined to require an offset and a base register. Since no base register is specified, the assembler attempts to imply the base register and compute the offset based upon information given in previous .BASE directives. In the last three instructions, the address argument is within -32,768 to +32,767 of the base address known to be in R1 (that is, COMM_AREA). Therefore, R1 is selected as the base register. The assembler also computes the correct offset from the base address known to be in R1 to the address specified in the instruction argument. Example 2 The assembler performs a sequential search through the list of possible base registers, R0 through R31. It uses the first definition possible if multiple base registers are valid. For example: .BASE R5, 300 : LDQ R10, 100 The assembler outputs the LDQ instruction as follows: LDQ R10, -200(R5) Both R31 and R5 are defined as base registers that can be used in constructing the instruction argument. R31 always contains 0. In this example, R5 is also known to contain the constant 300. The assembler uses the first base register, starting at R0 and progressing to R31, which provides a known value within -32,768 to +32,767 of the specified argument value. Since the assembler considers R5 before it considers R31, R5 is used rather than R31.