 |
VAX MACRO and Instruction Set Reference Manual
5.1.8 Literal Mode
In literal mode, the value of the literal is stored in the addressing
mode byte.
Formats
#literal
S^#literal
Parameters
literal
An expression, an integer constant, or a floating-point constant. The
literal must fit in the short literal form. That is, integers must be
in the range 0 to 63 and floating-point constants must be one of the 64
values listed in Table 5-2 and Table 5-3. Floating-point short
literals are stored with a 3-bit exponent and a 3-bit fraction.
Table 5-2 and Table 5-3 also show the value of the exponent and
the fraction for each literal. See Section 8.7.8 for information on the
format of short literals.
Table 5-2 Floating-Point Literals Expressed as Decimal Numbers
Exponent |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
0
|
0.5
|
0.5625
|
0.625
|
0.6875
|
0.75
|
0.8125
|
0.875
|
0.9375
|
1
|
1.0
|
1.125
|
1.25
|
1.37
|
1.5
|
1.625
|
1.75
|
1.875
|
2
|
2.0
|
2.25
|
2.5
|
2.75
|
3.0
|
3.25
|
3.5
|
3.75
|
3
|
4.0
|
4.5
|
5.0
|
5.5
|
6.0
|
6.5
|
7.0
|
7.5
|
4
|
8.0
|
9.0
|
10.0
|
11.0
|
12.0
|
13.0
|
14.0
|
15.0
|
5
|
16.0
|
18.0
|
20.0
|
22.0
|
24.0
|
26.0
|
28.0
|
30.0
|
6
|
32.0
|
36.0
|
40.0
|
44.0
|
48.0
|
52.0
|
56.0
|
60.0
|
7
|
64.0
|
72.0
|
80.0
|
88.0
|
96.0
|
104.0
|
112.0
|
120.0
|
Table 5-3 Floating-Point Literals Expressed as Rational Numbers
Exponent |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
0
|
1/2
|
9/16
|
5/8
|
11/16
|
3/4
|
13/16
|
7/8
|
15/16
|
1
|
1
|
1-1/8
|
1-1/4
|
1-3/8
|
1-1/2
|
1-5/8
|
1-3/4
|
1-7/8
|
2
|
2
|
2-1/4
|
2-1/2
|
2-3/4
|
3
|
3-1/4
|
3-1/2
|
3-3/4
|
3
|
4
|
4-1/2
|
5
|
5-1/2
|
6
|
6-1/2
|
7
|
7-1/2
|
4
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
15
|
5
|
16
|
18
|
20
|
22
|
24
|
26
|
28
|
30
|
6
|
32
|
36
|
40
|
44
|
48
|
52
|
56
|
60
|
7
|
64
|
72
|
80
|
88
|
96
|
104
|
112
|
120
|
Example
MOVL #1,R0 ; R0 is set to 1; the 1 is stored
; in the instruction as a short
; literal.
MOVB S^#CR,R1 ; The low byte of R1 is set
; to the value CR.
; CR is stored in the instruction
; as a short literal.
; If CR is not in range 0-63,
; the linker produces a
; truncation error.
MOVF #0.625,R6 ; R6 is set to the floating-point
; value 0.625; it is stored
; in the floating-point short
; literal form.
|
Notes
- When you use the #literal format, the assembler chooses whether to
use literal mode or immediate mode (see Section 5.2.4). The assembler
uses immediate mode if any of the following conditions is satisfied:
- The value of the literal does not fit in the short literal form.
- The literal is a relocatable or external expression (see
Section 3.5).
- The literal is an expression that contains undefined symbols.
The difference between immediate mode and literal mode is the
amount of storage that it takes to store the literal in the instruction.
- The S^#literal format forces the assembler to use literal mode.
5.2 Program Counter Modes
The program counter (PC) modes use the PC for a general register.
Following are the five program counter modes:
- Relative
- Relative deferred
- Absolute
- Immediate
- General
In Section 8.8, Table 8-6 is a summary of PC addressing.
5.2.1 Relative Mode
In relative mode, the address specified is the address of the operand.
The assembler stores the address as a displacement from the PC.
Relative mode can be used with index mode (see Section 5.3).
Format
Parameters
address
An expression specifying an address; the expression can be preceded by
one of the following displacement length specifiers, which indicate the
number of bytes needed to store the displacement.
Displacement Length Specifier |
Meaning |
B^
|
Displacement requires 1 byte.
|
W^
|
Displacement requires one word (2 bytes).
|
L^
|
Displacement requires one longword (4 bytes).
|
If no displacement length specifier precedes the address expression,
and the value of the expression is known, the assembler chooses the
smallest number of bytes (1, 2, or 4) needed to store the displacement.
If no length specifier precedes the address expression, and the value
of the expression is unknown, the assembler uses the default
displacement length (see the description of .DEFAULT in Chapter 6).
If the address expression is either defined later in the program or
defined in another program section, the assembler considers the value
unknown.
Example
MOVL LABEL,R1 ; Get longword at LABEL; the
; assembler uses default
; displacement unless LABEL was
; previously defined in this
; section
CMPL W^<DATA+4>,R10 ; Compare R10 with longword at
; address DATA+4; CMPL
; uses a word displacement
|
5.2.2 Relative Deferred Mode
In relative deferred mode, the address specified is the address of the
operand address (a pointer to the operand). The assembler stores the
address specified as a displacement from the PC.
Relative deferred mode can be used with index mode (see Section 5.3).
Format
Parameters
address
An expression specifying an address; the expression can be preceded by
one of the following displacement length specifiers, which indicate the
number of bytes needed to store the displacement:
Displacement Length Specifier |
Meaning |
B^
|
Displacement requires 1 byte.
|
W^
|
Displacement requires one word (2 bytes).
|
L^
|
Displacement requires one longword (4 bytes).
|
If no displacement length specifier precedes the address expression,
and the value of the expression is known, the assembler chooses the
smallest number of bytes (1, 2, or 4) needed to store the displacement.
If no length specifier precedes the address expression, and the value
of the expression is unknown, the assembler uses the default
displacement length (see the description of .DEFAULT in Chapter 6).
If the address expression is either defined later in the program or
defined in another program section, the assembler considers the value
unknown.
Example
CLRL @W^PNTR ; Clear longword pointed to by
; longword at PNTR; the assembler
; uses a word displacement
INCB @L^COUNTS+4 ; Increment byte pointed to by
; longword at COUNTS+4; assembler
; uses a longword displacement
|
5.2.3 Absolute Mode
In absolute mode, the address specified is the address of the operand.
The address is stored as an absolute virtual address (compare relative
mode, where the address is stored as a displacement from the PC).
Absolute mode can be used with index mode (see Section 5.3).
Format
Parameters
address
An expression specifying an address.
Example
CLRL @#^X1100 ; Clear the contents of location 1100(hex)
CLRB @#ACCOUNT ; Clear the contents of location
; ACCOUNT; the address is stored
; absolutely, not as a displacement
CALLS #3,@#SYS$FAO ; Call the procedure SYS$FAO with
; three arguments on the stack
|
5.2.4 Immediate Mode
In immediate mode, the literal specified is the operand.
Formats
#literal
I^#literal
Parameters
literal
An expression, an integer constant, or a floating-point constant.
Example
MOVL #1000,R0 ; R0 is set to 1000; the operand 1000
; is stored in a longword
MOVB #BAR,R1 ; The low byte of R1 is set
; to the value of BAR
MOVF #0.1,R6 ; R6 is set to the floating-point
; value 0.1; it is stored
; as a 4-byte floating-point
; value (it cannot be
; represented as a short literal)
ADDL2 I^#5,R0 ; The 5 is stored in a longword
; because the I^ forces the
; assembler to use immediate mode
MOVG #0.2,R6 ; The value 0.2 is converted
; to its G_FLOATING representation
MOVG #PI,R6 ; The value contained in PI is
; moved to R6; no conversion is
; performed
|
Notes
- When you use the #literal format, the assembler chooses whether to
use literal mode ( Section 5.1.8) or immediate mode. If the literal is
an integer from 0 to 63 or a floating-point constant that fits in the
short literal form, the assembler uses literal mode. If the literal is
an expression, the assembler uses literal mode if all the following
conditions are met:
- The expression is absolute.
- The expression contains no undefined symbols.
- The value of the expression fits in the short literal form.
In all other cases, the assembler uses immediate mode. The
difference between immediate mode and literal mode is the amount of
storage required to store the literal in the instruction. The assembler
stores an immediate mode literal in a byte, word, or longword depending
on the operand data type.
- The I^#literal format forces the assembler to use immediate mode.
- You can specify floating-point numbers two ways: as a numeric value
or as a symbol name. The assembler handles these values in different
ways, as follows:
- Numeric values are converted to the appropriate internal
floating-point representation.
- Symbols are not converted. The assembler assumes that the values
have already been converted to internal floating-point representation.
Once the assembler obtains the value, it tries to convert the internal
representation of the value to a short floating literal. If conversion
fails, the assembler uses immediate mode; if conversion succeeds, the
assembler uses short floating literal mode.
5.2.5 General Mode
In general mode, the address you specify is the address of the operand.
The linker converts the addressing mode to either relative or absolute
mode. If the address is relocatable, the linker converts general mode
to relative mode. If the address is absolute, the linker converts
general mode to absolute mode. You should use general mode to write
position-independent code when you do not know whether the address is
relocatable or absolute. A general addressing mode operand requires 5
bytes of storage.
You can use general mode with index mode (see Section 5.3).
Format
Parameters
address
An expression specifying an address.
Example
CLRL G^LABEL_1 ; Clears the longword at LABEL_1
; If LABEL_1 is defined as
; absolute then general mode is
; converted to absolute
; mode; if it is defined as
; relocatable, then general mode is
; converted to relative mode
CALLS #5,G^SYS$SERVICE ; Calls procedure SYS$SERVICE
; with 5 arguments on stack
|
5.3 Index Mode
Index mode is a general register mode that can be used only in
combination with another mode (the base mode). The base mode can be any
addressing mode except register, immediate, literal, index, or branch.
The assembler first evaluates the base mode to get the base address. To
get the operand address, the assembler multiplies the contents of the
index register by the number of bytes of the operand data type, then
adds the result to the base address.
Combining index mode with the other addressing modes produces the
following addressing modes:
- Register deferred index
- Autoincrement index
- Autoincrement deferred index
- Autodecrement index
- Displacement index
- Displacement deferred index
- Relative index
- Relative deferred index
- Absolute index
- General index
The process of first evaluating the base mode and then adding the index
register is the same for each of these modes.
Formats
base-mode[Rx]
base-mode[AP]
base-mode[FP]
base-mode[SP]
Parameters
base-mode
Any addressing mode except register, immediate, literal, index, or
branch, specifying the base address.
x
A number in the range 0 to 12, specifying the index register.
Table 5-4 lists the formats of index mode addressing.
Example
;
; Register deferred index mode
;
OFFS=20 ; Define OFFS
MOVAB BLIST,R9 ; Get address of BLIST
MOVL #OFFS,R1 ; Set up index register
CLRB (R9)[R1] ; Clear byte whose address
; is the address of BLIST
; plus 20*1
CLRQ (R9)[R1] ; Clear quadword whose
; address is the address
; of BLIST plus 20*8
CLRO (R9)[R1] ; Clear octaword whose
; address is the address
; of BLIST plus 20*16
;
; Autoincrement index mode
;
CLRW (R9)+[R1] ; Clear word whose address
; is address of BLIST plus
; 20*2; R9 now contains
; address of BLIST+2
;
; Autoincrement deferred index mode
;
MOVAL POINT,R8 ; Get address of POINT
MOVL #30,R2 ; Set up index register
CLRW @(R8)+[R2] ; Clear word whose address
; is 30*2 plus the address
; stored in POINT; R8 now
; contains 4 plus address of
; POINT
;
; Displacement deferred index mode
;
MOVAL ADDARR,R9 ; Get address of address array
MOVL #100,R1 ; Set up index register
TSTF @40(R9)[R1] ; Test floating-point value
; whose address is 100*4 plus
; the address stored at
; (ADDARR+40)
|
Table 5-4 Index Mode Addressing
Mode |
Format |
Register Deferred Index
1,2
|
(Rn)[Rx]
|
Autoincrement Index
1,2
|
(Rn)+[Rx]
|
Autoincrement Deferred
Index
1,2
|
@(Rn)+[Rx]
|
Autodecrement Index
1,2
|
-(Rn)[Rx]
|
Displacement Index
1,2,3
|
dis(Rn)[Rx]
|
Displacement Deferred
Index
1,2,3
|
@dis(Rn)[Rx]
|
Relative Index
2
|
address[Rx]
|
Relative Deferred Index
2
|
@address[Rx]
|
Absolute Index
2
|
@#address[Rx]
|
General Index
2
|
G^address[Rx]
|
1Rn---Any general register R0 to R12 or the AP, FP, or SP
register.
2Rx---Any general register R0 to R12 or the AP, FP, or SP
register. Rx cannot be the same register as Rn in the autoincrement
index, autoincrement deferred index, and decrement index addressing
modes.
3dis---An expression specifying a displacement.
Notes
- If the base mode alters the contents of its register
(autoincrement, autoincrement deferred, and autodecrement), the index
mode cannot specify the same register.
- The index register is added to the address after the base mode is
completely evaluated. For example, in autoincrement deferred index
mode, the base register contains the address of the operand address.
The index register (times the length of the operand data type) is added
to the operand address rather than to the address stored in the base
register.
|