3.1.4 Immediate Addressing
In Immediate Addressing, the instruction encoding contains a predefined constant operand that is used by the instruction. This addressing mode may be used independently, but it is more frequently combined with the File Register, Direct and Indirect Addressing modes. The size of the immediate operand which may be used varies with the instruction type. Constants of size 1-bit (#lit1), 5-bit (#bit5, #lit5 and #Slit5), 7-bit (#lit7), 6-bit (#Slit6), 8-bit (#lit8), 14-bit (#Slit14), 16-bit (#lit16), 20-bit(#lit20, #Slit20), and 32-bit(#lit32) may be used. Constants may be signed or unsigned, and the symbols #Slit6, #Slit8, and #Slit20 designate a signed constant. All other immediate constants are unsigned. Table 3-4 shows the usage of each immediate operand in the instruction set.
| Operand | Instruction Usage |
|---|---|
#lit1 | PWRSAV |
#lit3 | CTXTSWP DISICTL |
#bit5 | BCLR, BSET, CLRWDT, BTG, BTST,
BTSTS |
#lit5 | ASR, LSR, SL |
#wid6 | BFEXT, BFINS |
#lit7 | ADD, ADDC, AND, CP, CPB, IOR, SUB, SUBB, SUBBR,
SUBR, XOR |
#Slit6 | SFTAC |
#lit8 | MOV.B, MULSU, MULUU, MULIUU, MULISU |
#lit7 | ADD, ADDC, AND, CP, CPB, IOR, RETLW, SUB, SUBB, XOR |
#Slit6 | LAC, LLAC, LUAC, SAC, SLAC, SUAC,
SFTAC, SACR, SUB |
#lit16 | LNK, RETLW, MOV, SUB, SUBB, XOR, ADD, ADDC, AND, CP,
IOR |
#lit20 | REPEAT |
#lit16 | MOV |
#lit32 | MOV, CALL, GOTO |
The syntax for Immediate Addressing requires that the number sign (#) must immediately precede the constant operand value. The “#” symbol indicates to the assembler that the quantity is a constant. If an out-of-range constant is used with an instruction, the assembler will generate an error. Several examples of Immediate Addressing are shown in Immediate Addressing.
Immediate Addressing
PWRSAV #1 ; Enter IDLE mode
ADD.B #0x10, W0 ; Add 0x10 to W0 (byte mode)Before Instruction:
W0 = 0x12A9After Instruction:
W0 = 0x12B9
XOR W0, #1, [W1++] ; Exclusive-OR W0 and 0x1
; Store the result to [W1]
; Post-increment W1Before Instruction:
W0 = 0xFFFF
W1 = 0x0890
Data Memory 0x0890 = 0x0032After Instruction:
W0 = 0xFFFF
W1 = 0x0892
Data Memory 0x0890 = 0xFFFE